-
Notifications
You must be signed in to change notification settings - Fork 172
feat(BA-5504): Update file operation services to set vfolder updated_at on mutations
#10821
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Update file operation services to set vfolder `updated_at` timestamp on mutations (upload, rename, move, delete). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| """Add `updated_at` column to `vfolders` | ||
|
|
||
| Revision ID: 5a139f0e951e | ||
| Revises: 9dc6609c92ce | ||
| Create Date: 2026-04-07 | ||
|
|
||
| """ | ||
|
|
||
| import sqlalchemy as sa | ||
| from alembic import op | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "5a139f0e951e" | ||
| down_revision = "9dc6609c92ce" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| op.add_column( | ||
| "vfolders", | ||
| sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True), | ||
| ) | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| op.drop_column("vfolders", "updated_at") | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,5 +1,6 @@ | ||||||||||
| import uuid | ||||||||||
| from collections.abc import Mapping, Sequence | ||||||||||
| from collections.abc import AsyncIterator, Mapping, Sequence | ||||||||||
| from contextlib import asynccontextmanager as actxmgr | ||||||||||
| from datetime import UTC, datetime | ||||||||||
| from typing import Any, cast | ||||||||||
|
|
||||||||||
|
|
@@ -412,6 +413,27 @@ async def update_vfolder_attribute(self, updater: Updater[VFolderRow]) -> VFolde | |||||||||
| raise VFolderNotFound() | ||||||||||
| return self._vfolder_row_to_data(result.row) | ||||||||||
|
|
||||||||||
| @actxmgr | ||||||||||
| async def track_content_update(self, vfolder_id: uuid.UUID) -> AsyncIterator[None]: | ||||||||||
| """ | ||||||||||
| Context manager that updates ``updated_at`` after successful content | ||||||||||
| mutations (upload, rename, move, delete, mkdir). | ||||||||||
|
|
||||||||||
| If the wrapped block raises, ``updated_at`` is NOT touched. | ||||||||||
| """ | ||||||||||
| yield | ||||||||||
| await self._update_vfolder_updated_at(vfolder_id) | ||||||||||
|
|
||||||||||
| @vfolder_repository_resilience.apply() | ||||||||||
| async def _update_vfolder_updated_at(self, vfolder_id: uuid.UUID) -> None: | ||||||||||
| async with self._db.begin_session() as session: | ||||||||||
| query = ( | ||||||||||
| sa.update(VFolderRow) | ||||||||||
| .where(VFolderRow.id == vfolder_id) | ||||||||||
| .values(updated_at=sa.func.now()) | ||||||||||
| ) | ||||||||||
| await session.execute(query) | ||||||||||
|
||||||||||
| await session.execute(query) | |
| result = await session.execute(query) | |
| if result.rowcount == 0: | |
| raise VFolderNotFound() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A vfolder_id that does not exist in the call path cannot be provided. The track_content_update method is called only after the file operation service has verified the existence of the vfolder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it okay not to set last_used or a default value for updated_at?