| 107 | return result |
| 108 | |
| 109 | async def update(self, user: User, source: Union[dict, SQLModel, None] = None): |
| 110 | old_name = user.name |
| 111 | result = await user.update(self.session, source, auto_commit=False) |
| 112 | # Refresh denormalized ``user_name`` snapshots on usage rows so |
| 113 | # dashboards reflect the new name. Bundled in the same |
| 114 | # transaction as the user-row write so a rollback rolls back |
| 115 | # both. See :func:`propagate_user_rename` for scope notes. |
| 116 | if user.name != old_name: |
| 117 | await propagate_user_rename(self.session, user.id, user.name) |
| 118 | await self.session.commit() |
| 119 | await delete_cache_by_key(self.get_by_id, user.id) |
| 120 | await delete_cache_by_key(self.get_user_accessible_model_names, user.id) |
| 121 | await delete_cache_by_key(self.get_by_username, user.name) |
| 122 | if old_name != user.name: |
| 123 | await delete_cache_by_key(self.get_by_username, old_name) |
| 124 | return result |
| 125 | |
| 126 | async def delete(self, user: User): |
| 127 | apikeys = await APIKeyService(self.session).get_by_user_id(user.id) |