diff options
author | Pierre-Yves Chibon <pingou@pingoured.fr> | 2012-04-19 20:35:22 +0200 |
---|---|---|
committer | Pierre-Yves Chibon <pingou@pingoured.fr> | 2012-04-19 20:35:22 +0200 |
commit | 0f9392d79a232711979da162fb81fd58ba319c94 (patch) | |
tree | acb85e39c291d569d95038e5421af8cf6ae31075 | |
parent | 0de692b3489435ae78187f69627865a860a281a6 (diff) | |
download | hyperkitty-0f9392d79a232711979da162fb81fd58ba319c94.tar.gz hyperkitty-0f9392d79a232711979da162fb81fd58ba319c94.tar.xz hyperkitty-0f9392d79a232711979da162fb81fd58ba319c94.zip |
Limit the result of the tag search to the lastest 50
-rw-r--r-- | lib/mongo.py | 14 | ||||
-rw-r--r-- | views/pages.py | 6 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lib/mongo.py b/lib/mongo.py index b202001..9344932 100644 --- a/lib/mongo.py +++ b/lib/mongo.py @@ -176,13 +176,23 @@ def get_archives_length(table): return archives -def search_archives(table, query): +def search_archives(table, query, limit=None): db = connection[table] db.mails.create_index('Date') db.mails.ensure_index('Date') for el in query: db.mails.create_index(str(el)) db.mails.ensure_index(str(el)) - return list(db.mails.find(query, sort=[('Date', + output = [] + try: + limit = int(limit) + except ValueError: + limit = None + if limit: + output = list(db.mails.find(query, sort=[('Date', + pymongo.DESCENDING)]).limit(limit)) + else: + output = list(db.mails.find(query, sort=[('Date', pymongo.DESCENDING)])) + return output diff --git a/views/pages.py b/views/pages.py index 6ed9964..6537a41 100644 --- a/views/pages.py +++ b/views/pages.py @@ -237,11 +237,11 @@ def message (request, mlist_fqdn, messageid): return HttpResponse(t.render(c)) def _search_results_page(request, mlist_fqdn, query_string, search_type, - page=1, num_threads=25): + page=1, num_threads=25, limit=None): search_form = SearchForm(auto_id=False) t = loader.get_template('search.html') list_name = mlist_fqdn.split('@')[0] - threads = mongo.search_archives(list_name, query_string) + threads = mongo.search_archives(list_name, query_string, limit=limit) res_num = len(threads) participants = set() @@ -326,7 +326,7 @@ def search_tag(request, mlist_fqdn, tag=None, page=1): else: query_string = None return _search_results_page(request, mlist_fqdn, query_string, - 'Tag search', page) + 'Tag search', page, limit=50) def thread (request, mlist_fqdn, threadid): ''' Displays all the email for a given thread identifier ''' |