feat: high-concurrency userid hashing
This commit is contained in:
@@ -2,15 +2,25 @@ from decimal import Decimal, getcontext
|
||||
import hashlib
|
||||
|
||||
import orjson as json
|
||||
from diskcache import Cache
|
||||
|
||||
getcontext().prec = 28
|
||||
|
||||
CACHE = Cache("target")
|
||||
|
||||
|
||||
def salted_hash_userid(user_id: int):
|
||||
hex = CACHE.get(user_id)
|
||||
if hex is not None:
|
||||
return hex
|
||||
|
||||
SALT = b"Lt2N5xgjJOqRsT5qVt7wWYw6SqOPZDI7"
|
||||
|
||||
hash_uid = hashlib.sha256(f"{user_id}".encode("utf-8") + SALT)
|
||||
return hash_uid.hexdigest()[:16]
|
||||
result = hash_uid.hexdigest()[:16]
|
||||
|
||||
CACHE.add(user_id, result)
|
||||
return result
|
||||
|
||||
|
||||
def dx_rating(difficulty: Decimal, achievement: int) -> int:
|
||||
|
||||
Reference in New Issue
Block a user