Skip to content

Commit

Permalink
Merge pull request #31 from mdavis332/feature/compactDb
Browse files Browse the repository at this point in the history
Compact db collections on init to give back OS space
  • Loading branch information
JesseBowling authored Nov 21, 2019
2 parents 99e1863 + 07331fd commit fd744b4
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion mnemosyne/persistance/mnemodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, host, port, database_name, indexttl=False):
self.rg = ReportGenerator(host=host, port=port, database_name=database_name)
self.db = conn[database_name]
self.ensure_index(indexttl)
self.compact_database()

def ensure_index(self, indexttl):
self.db.hpfeed.ensure_index([('normalized', 1), ('last_error', 1)], unique=False, background=True)
Expand Down Expand Up @@ -96,7 +97,14 @@ def set_coll_indexttl(self, coll, indexttl):
})
#self.db.session.ensure_index('timestamp', unique=False, background=True)
#self.db.hpfeed.ensure_index('timestamp', unique=False, background=True)


def compact_database(self):
# runs 'compact' on each collection in mongodb to free any available space back to OS
# warning: 'compact' _IS_ a blocking operation
collections = self.db.collection_names()
for collection in collections:
logger.info('Compacting collection %s', collection)
self.db.command('compact', collection, force=True)

def insert_normalized(self, ndata, hpfeed_id, identifier=None):
assert isinstance(hpfeed_id, ObjectId)
Expand Down

0 comments on commit fd744b4

Please sign in to comment.