Add TTL index creation:

Add TTL indexed for "users" and "registration" collections
This commit is contained in:
Fred Boniface 2023-04-04 21:48:48 +01:00
parent 9a58b5eb60
commit cab6a429e2
2 changed files with 9 additions and 0 deletions

View File

@ -53,6 +53,10 @@ if corpusAge > 1036800:
else: else:
log.out('main.py: Not updating stations data', "INFO") log.out('main.py: Not updating stations data', "INFO")
log.out('main.py: Requesting TTL Index Creation', "INFO")
mongo.createTtlIndex("users", "atime", 31557600)
mongo.createTtlIndex("registrations", "time", 1800)
# Push version number to database for reporting # Push version number to database for reporting
mongo.putVersion(version) mongo.putVersion(version)

View File

@ -44,6 +44,11 @@ def createSingleIndex(collection, field):
log.out(f'mongo.createSingleIndex: Created index of {field} in {collection}', "INFO") log.out(f'mongo.createSingleIndex: Created index of {field} in {collection}', "INFO")
return return
def createTtlIndex(collection, field, time):
col = db[collection]
col.create_index(field, expireAfterSeconds = time)
log.out(f'mongo.createTtlIndex: Created TTL Index of {field} in {collection} to expire after {time} seconds', "INFO")
def putBulkCorpus(data): def putBulkCorpus(data):
collection = "corpus" collection = "corpus"
startCount = getLength(collection) startCount = getLength(collection)