def search_page(): logger.info("in search_page") logger.info(request.url) result = None if USE_REDIS: with Bench("Trying Redis cache"): key = "search_results:v1:" + json.dumps(request.args, sort_keys=True) logger.debug("key is:", pf(key)) result = Redis.get(key) if result: logger.info("Redis cache hit on search results!") result = pickle.loads(result) else: logger.info("Skipping Redis cache (USE_REDIS=False)") logger.info("request.args is", request.args) the_search = search_results.SearchResultPage(request.args) result = the_search.__dict__ valid_search = result['search_term_exists'] logger.debugf("result", result) if USE_REDIS and valid_search: Redis.set(key, pickle.dumps(result, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60 * 60) if valid_search: return render_template("search_result_page.html", **result) else: return render_template("search_error.html")
def search_page_table(): logger.info("in search_page table") logger.info(request.url) logger.info("request.args is", request.args) the_search = search_results.SearchResultPage(request.args) logger.info(type(the_search.trait_list)) logger.info(the_search.trait_list) current_page = server_side.ServerSideTable( len(the_search.trait_list), the_search.trait_list, the_search.header_data_names, request.args, ).get_page() return flask.jsonify(current_page)
def search_page(): logger.info("in search_page") if 'info_database' in request.args: logger.info("Going to sharing_info_page") template_vars = sharing_info_page() if template_vars.redirect_url: logger.info("Going to redirect") return flask.redirect(template_vars.redirect_url) else: return render_template("data_sharing.html", **template_vars.__dict__) else: result = None if USE_REDIS: with Bench("Trying Redis cache"): key = "search_results:v1:" + json.dumps(request.args, sort_keys=True) logger.debug("key is:", pf(key)) result = Redis.get(key) if result: logger.info("Redis cache hit on search results!") result = pickle.loads(result) else: logger.info("Skipping Redis cache (USE_REDIS=False)") logger.info("request.args is", request.args) the_search = search_results.SearchResultPage(request.args) result = the_search.__dict__ logger.debugf("result", result) if USE_REDIS: Redis.set(key, pickle.dumps(result, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60 * 60) if result['search_term_exists']: return render_template("search_result_page.html", **result) else: return render_template("search_error.html")
def search_page(): print("in search_page") if 'info_database' in request.args: print("Going to sharing_info_page") template_vars = sharing_info_page() if template_vars.redirect_url: print("Going to redirect") return flask.redirect(template_vars.redirect_url) else: return render_template("data_sharing.html", **template_vars.__dict__) else: key = "search_results:v1:" + json.dumps(request.args, sort_keys=True) print("key is:", pf(key)) with Bench("Loading cache"): result = Redis.get(key) if result: print("Cache hit!!!") with Bench("Loading results"): result = pickle.loads(result) else: print("calling search_results.SearchResultPage") print("request.args is", request.args) the_search = search_results.SearchResultPage(request.args) result = the_search.__dict__ print("result: ", pf(result)) Redis.set(key, pickle.dumps(result, pickle.HIGHEST_PROTOCOL)) Redis.expire(key, 60 * 60) if result['quick']: return render_template("quick_search.html", **result) elif result['search_term_exists']: return render_template("search_result_page.html", **result) else: return render_template("search_error.html")