diff options
Diffstat (limited to 'gn_auth/auth/authorisation/users/collections/models.py')
-rw-r--r-- | gn_auth/auth/authorisation/users/collections/models.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/gn_auth/auth/authorisation/users/collections/models.py b/gn_auth/auth/authorisation/users/collections/models.py index 9157100..9397094 100644 --- a/gn_auth/auth/authorisation/users/collections/models.py +++ b/gn_auth/auth/authorisation/users/collections/models.py @@ -10,8 +10,8 @@ from ...errors import InvalidData, NotFoundError from ..models import User +REDIS_COLLECTIONS_KEY = "collections2" __OLD_REDIS_COLLECTIONS_KEY__ = "collections" -__REDIS_COLLECTIONS_KEY__ = "collections2" class CollectionJSONEncoder(json.JSONEncoder): """Serialise collection objects into JSON.""" @@ -96,7 +96,7 @@ def __retrieve_old_user_collections__(rconn: Redis, old_user_id: UUID) -> tuple: def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: """Retrieve current user collections.""" collections = tuple(parse_collection(coll) for coll in json.loads( - rconn.hget(__REDIS_COLLECTIONS_KEY__, str(user.user_id)) or + rconn.hget(REDIS_COLLECTIONS_KEY, str(user.user_id)) or "[]")) old_accounts = __retrieve_old_accounts__(rconn) if (user.email in old_accounts and @@ -109,7 +109,7 @@ def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: }.values()) __toggle_boolean_field__(rconn, user.email, "collections-migrated") rconn.hset( - __REDIS_COLLECTIONS_KEY__, + REDIS_COLLECTIONS_KEY, key=str(user.user_id), value=json.dumps(collections, cls=CollectionJSONEncoder)) return collections @@ -117,7 +117,7 @@ def user_collections(rconn: Redis, user: User) -> tuple[dict, ...]: def save_collections(rconn: Redis, user: User, collections: tuple[dict, ...]) -> tuple[dict, ...]: """Save the `collections` to redis.""" rconn.hset( - __REDIS_COLLECTIONS_KEY__, + REDIS_COLLECTIONS_KEY, str(user.user_id), json.dumps(collections, cls=CollectionJSONEncoder)) return collections |