Merge pull request #276 from diamante0018/main

fix DB cache
This commit is contained in:
Dylan 2025-04-22 21:53:48 +01:00 committed by GitHub
commit c2ed8aa884
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -49,7 +49,9 @@ def addVnfToTweetIdCache(tweet_id, vnf):
global link_cache
try:
if link_cache_system == "db":
out = db.linkCache.update_one(vnf)
filter_query = {'tweet': tweet_id}
update_operation = {'$set': vnf}
out = db.linkCache.update_one(filter_query, update_operation, upsert=True)
log.debug("Link added to DB cache ")
return True
elif link_cache_system == "json":
@ -86,7 +88,7 @@ def getVnfFromTweetIdCache(tweet_id):
collection = db.linkCache
vnf = collection.find_one({'tweet': tweet_id})
if vnf != None:
hits = ( vnf['hits'] + 1 )
hits = ( vnf.get('hits', 0) + 1 )
log.debug("Link located in DB cache.")
query = { 'tweet': tweet_id }
change = { "$set" : { "hits" : hits } }