aboutsummaryrefslogtreecommitdiff
path: root/source/mongodb.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel@gmail.com>2013-04-02 07:53:35 +0200
committerCédric Bonhomme <kimble.mandel@gmail.com>2013-04-02 07:53:35 +0200
commit8d2bdf02fb163cf83d9a6d0303319507474ede15 (patch)
treec5efe5064845debe1f9c8eafb009dbcb247edb66 /source/mongodb.py
parentTest if ids of the feed/articles exists. (diff)
downloadnewspipe-8d2bdf02fb163cf83d9a6d0303319507474ede15.tar.gz
newspipe-8d2bdf02fb163cf83d9a6d0303319507474ede15.tar.bz2
newspipe-8d2bdf02fb163cf83d9a6d0303319507474ede15.zip
Index are generated in background at database initialization.
Diffstat (limited to 'source/mongodb.py')
-rw-r--r--source/mongodb.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/source/mongodb.py b/source/mongodb.py
index f0aa730a..964c79a4 100644
--- a/source/mongodb.py
+++ b/source/mongodb.py
@@ -39,14 +39,21 @@ class Articles(object):
self.connection = pymongo.connection.Connection(url, port)
self.db = pymongo.database.Database(self.connection, self.db_name)
self.db.authenticate(user, password)
+ collections = self.db.collection_names()
+ for collection_name in collections:
+ if collection_name != "system.indexes":
+ self.db[collection_name].ensure_index([("article_date", pymongo.DESCENDING)], \
+ name="date_index", unique=False, \
+ background=True)
+ self.db[collection_name].ensure_index([('article_content', pymongo.ASCENDING)], \
+ name="content_index", unique=False, \
+ background=True)
def add_collection(self, new_collection):
"""
Creates a new collection for a new feed.
"""
collection = self.db[new_collection["feed_id"]]
- collection.create_index([("article_date", pymongo.DESCENDING)], {"unique":False, "sparse":False})
- collection.ensure_index('article_content', pymongo.ASCENDING)
collection.insert(new_collection)
def add_articles(self, articles, feed_id):
bgstack15