Add in-memory read cache with CUD-based invalidation

This commit is contained in:
Chris
2026-04-03 02:32:38 +08:00
parent e912d1498e
commit 55e640f2fb
6 changed files with 194 additions and 20 deletions

View File

@@ -57,6 +57,7 @@ class UsersRepository:
provider_user_id: str | None = None,
) -> User:
user = self.get_by_sub(user_sub)
changed = False
if user is None:
user = User(
user_sub=user_sub,
@@ -68,17 +69,30 @@ class UsersRepository:
status=status,
)
self.db.add(user)
changed = True
else:
if provider_user_id is not None:
if provider_user_id is not None and user.provider_user_id != provider_user_id:
user.provider_user_id = provider_user_id
user.username = username
user.email = email
user.display_name = display_name
user.is_active = is_active
user.status = status
changed = True
if user.username != username:
user.username = username
changed = True
if user.email != email:
user.email = email
changed = True
if user.display_name != display_name:
user.display_name = display_name
changed = True
if user.is_active != is_active:
user.is_active = is_active
changed = True
if user.status != status:
user.status = status
changed = True
self.db.commit()
self.db.refresh(user)
if changed:
self.db.commit()
self.db.refresh(user)
return user
def update_member(