fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 17s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 9s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 7s
All checks were successful
Deploy Dev / Build (pull_request) Successful in 17s
Deploy Dev / Push (pull_request) Successful in 10s
Deploy Dev / Deploy dev (pull_request) Successful in 9s
Deploy Prod / Build (pull_request) Successful in 5s
Deploy Prod / Push (pull_request) Successful in 9s
Deploy Prod / Deploy prod (pull_request) Successful in 7s
This commit is contained in:
parent
32377d93fe
commit
fb7716e8fb
@ -15,6 +15,7 @@ services:
|
|||||||
- /var/run/docker.sock:/var/run/docker.sock
|
- /var/run/docker.sock:/var/run/docker.sock
|
||||||
networks:
|
networks:
|
||||||
- configurator
|
- configurator
|
||||||
|
- queues
|
||||||
deploy:
|
deploy:
|
||||||
mode: replicated
|
mode: replicated
|
||||||
restart_policy:
|
restart_policy:
|
||||||
@ -28,3 +29,5 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
configurator:
|
configurator:
|
||||||
external: true
|
external: true
|
||||||
|
queues:
|
||||||
|
external: true
|
||||||
|
42
storage.py
42
storage.py
@ -1,42 +0,0 @@
|
|||||||
from cachetools import TTLCache
|
|
||||||
import os
|
|
||||||
|
|
||||||
from utils.mongo import mongo
|
|
||||||
|
|
||||||
CACHE_SIZE = int(os.getenv("CACHE_SIZE", 1000))
|
|
||||||
CACHE_TTL = int(os.getenv("CACHE_TTL", 3600))
|
|
||||||
|
|
||||||
cache = TTLCache(CACHE_SIZE, CACHE_TTL)
|
|
||||||
|
|
||||||
|
|
||||||
def get_chat_info(chat_id: int) -> dict:
|
|
||||||
cached_info = cache.get(chat_id)
|
|
||||||
if cached_info is not None:
|
|
||||||
return cached_info
|
|
||||||
mongo_info = mongo.chats_collection.find_one({"chat_id": chat_id})
|
|
||||||
if mongo_info is not None:
|
|
||||||
cache[chat_id] = mongo_info
|
|
||||||
return mongo_info
|
|
||||||
chat_info = {"chat_id": chat_id, "state": "default", "probability": 100}
|
|
||||||
mongo.chats_collection.insert_one(chat_info)
|
|
||||||
cache[chat_id] = chat_info
|
|
||||||
return chat_info
|
|
||||||
|
|
||||||
|
|
||||||
def set_values(chat_id: int, **values):
|
|
||||||
cached_info = cache.get(chat_id)
|
|
||||||
if cached_info is None:
|
|
||||||
mongo_info = mongo.chats_collection.find_one({"chat_id": chat_id})
|
|
||||||
if mongo_info is None:
|
|
||||||
chat_info = {"chat_id": chat_id, "state": "default", "probability": 100}
|
|
||||||
chat_info.update(values)
|
|
||||||
mongo.chats_collection.insert_one(chat_info)
|
|
||||||
cache[chat_id] = chat_info
|
|
||||||
else:
|
|
||||||
mongo.chats_collection.update_one({"chat_id": chat_id}, {"$set": values})
|
|
||||||
mongo_info = dict(mongo_info)
|
|
||||||
mongo_info.update(values)
|
|
||||||
cache[chat_id] = mongo_info
|
|
||||||
else:
|
|
||||||
cached_info.update(values)
|
|
||||||
mongo.chats_collection.update_one({"chat_id": chat_id}, {"$set": values})
|
|
Loading…
Reference in New Issue
Block a user