diff options
author | Zachary Sloan | 2013-05-21 22:22:00 +0000 |
---|---|---|
committer | Zachary Sloan | 2013-05-21 22:22:00 +0000 |
commit | aeb0e9b723c296709381807af136ccc33b84365e (patch) | |
tree | d519f7ea625a123b5e5e700cfc3a161d8fc4ebc4 | |
parent | 668d6be6286c646cb1ce8cc4d415aa65640bc84c (diff) | |
download | genenetwork2-aeb0e9b723c296709381807af136ccc33b84365e.tar.gz |
Added caching to the search page (for both regular and quick searckes)
-rw-r--r-- | wqflask/wqflask/do_search.py | 8 | ||||
-rw-r--r-- | wqflask/wqflask/templates/index_page.html | 3 | ||||
-rw-r--r-- | wqflask/wqflask/views.py | 34 |
3 files changed, 27 insertions, 18 deletions
diff --git a/wqflask/wqflask/do_search.py b/wqflask/wqflask/do_search.py index 1b1b56fb..7b3e0869 100644 --- a/wqflask/wqflask/do_search.py +++ b/wqflask/wqflask/do_search.py @@ -36,7 +36,7 @@ class DoSearch(object): def execute(self, query): """Executes query and returns results""" query = self.normalize_spaces(query) - print("in do_search query is:", pf(query)) + #print("in do_search query is:", pf(query)) results = g.db.execute(query, no_parameters=True).fetchall() #results = self.cursor.fetchall() return results @@ -90,7 +90,7 @@ class QuickMrnaAssaySearch(DoSearch): AGAINST ('%s' IN BOOLEAN MODE)) """ % (escape(self.search_term[0])) - print("final query is:", pf(query)) + #print("final query is:", pf(query)) return self.execute(query) @@ -134,7 +134,7 @@ class MrnaAssaySearch(DoSearch): where_clause, escape(self.dataset.id))) - print("query is:", pf(query)) + #print("query is:", pf(query)) return query @@ -155,7 +155,7 @@ class MrnaAssaySearch(DoSearch): """ % (escape(self.search_term[0]), escape(str(self.dataset.id))) - print("final query is:", pf(query)) + #print("final query is:", pf(query)) return self.execute(query) diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html index 0cc1c353..b4376ce3 100644 --- a/wqflask/wqflask/templates/index_page.html +++ b/wqflask/wqflask/templates/index_page.html @@ -9,7 +9,6 @@ <div class="container"> <h1>GeneNetwork</h1> <p class="lead">Open source bioinformatics for systems genetics</p> - <p>- Lei Yan</p> </div> </header> @@ -43,11 +42,9 @@ class="btn btn-primary" value="Search"> </div> </fieldset> - </form> </section> <section id="search"> - <div class="page-header"> <h1>Select and search</h1> </div> diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 8531561a..1af324b2 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -76,17 +76,28 @@ def search_page(): else: return render_template("data_sharing.html", **template_vars.__dict__) else: - print("calling search_results.SearchResultPage") - the_search = search_results.SearchResultPage(request.args) - print("template_vars is:", pf(the_search.__dict__)) - #print("trait_list is:", pf(the_search.__dict__['trait_list'][0].__dict__)) - #for trait in the_search.trait_list: - # print(" -", trait.description_display) - - if the_search.quick: - return render_template("quick_search.html", **the_search.__dict__) + key = "search_results:v2:" + 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: - return render_template("search_result_page.html", **the_search.__dict__) + print("calling search_results.SearchResultPage") + the_search = search_results.SearchResultPage(request.args) + result = the_search.__dict__ + + print("result: ", pf(result)) + Redis.set(key, pickle.dumps(result)) + Redis.expire(key, 60*60) + + if result['quick']: + return render_template("quick_search.html", **result) + else: + return render_template("search_result_page.html", **result) @app.route("/whats_new") @@ -171,9 +182,10 @@ def marker_regression_page(): for key, value in initial_start_vars.iteritems(): if key in wanted or key.startswith(('value:')): start_vars[key] = value - + version = "v14" key = "marker_regression:{}:".format(version) + json.dumps(start_vars, sort_keys=True) + print("key is:", pf(key)) with Bench("Loading cache"): result = Redis.get(key) |