fix DB cache
This commit is contained in:
parent
84a19e9baa
commit
22828a1fc8
6
cache.py
6
cache.py
@ -49,7 +49,9 @@ def addVnfToTweetIdCache(tweet_id, vnf):
|
|||||||
global link_cache
|
global link_cache
|
||||||
try:
|
try:
|
||||||
if link_cache_system == "db":
|
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 ")
|
log.debug("Link added to DB cache ")
|
||||||
return True
|
return True
|
||||||
elif link_cache_system == "json":
|
elif link_cache_system == "json":
|
||||||
@ -86,7 +88,7 @@ def getVnfFromTweetIdCache(tweet_id):
|
|||||||
collection = db.linkCache
|
collection = db.linkCache
|
||||||
vnf = collection.find_one({'tweet': tweet_id})
|
vnf = collection.find_one({'tweet': tweet_id})
|
||||||
if vnf != None:
|
if vnf != None:
|
||||||
hits = ( vnf['hits'] + 1 )
|
hits = ( vnf.get('hits', 0) + 1 )
|
||||||
log.debug("Link located in DB cache.")
|
log.debug("Link located in DB cache.")
|
||||||
query = { 'tweet': tweet_id }
|
query = { 'tweet': tweet_id }
|
||||||
change = { "$set" : { "hits" : hits } }
|
change = { "$set" : { "hits" : hits } }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user