-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: derive last_accessed_at from claimed_at to unify timestamp tracking #16
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
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 | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -271,9 +271,8 @@ def blob_exists(self, hash: str) -> bool: | |||||||||
|
|
||||||||||
| def put_commit(self, commit: Commit) -> None: | ||||||||||
| conn = self._connect(immediate=True) | ||||||||||
| now = datetime.now(UTC).isoformat() | ||||||||||
| try: | ||||||||||
| self._put_commit_row(conn, commit, now) | ||||||||||
| self._put_commit_row(conn, commit, commit.claimed_at.isoformat()) | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The PR changes last_accessed_at to always equal claimed_at, and removes the side-effect update on reads. This is a breaking change for users relying on the old behavior (e.g., for monitoring or custom eviction logic). Add a note to the changelog and update the README or API docs to explain the new semantics. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The call commit.claimed_at.isoformat() may include a timezone offset if claimed_at is timezone-aware with a non-UTC offset. Other timestamps in the store use datetime.now(UTC).isoformat() which always appends +00:00. This could cause comparison issues if the two ISO strings are compared lexicographically. Ensure claimed_at is always in UTC before calling isoformat().
Suggested change
|
||||||||||
| conn.execute("COMMIT") | ||||||||||
| except Exception: | ||||||||||
| conn.execute("ROLLBACK") | ||||||||||
|
|
@@ -329,8 +328,7 @@ def _put_commit_row( | |||||||||
|
|
||||||||||
| def find_by_fingerprint(self, fingerprint: str) -> Commit | None: | ||||||||||
| conn = self._connect() | ||||||||||
| now = datetime.now(UTC) | ||||||||||
| now_iso = now.isoformat() | ||||||||||
| now_iso = datetime.now(UTC).isoformat() | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||
| row = conn.execute( | ||||||||||
| """SELECT * FROM commits | ||||||||||
| WHERE fingerprint = ? AND status IN ('completed', 'cached') | ||||||||||
|
|
@@ -341,10 +339,6 @@ def find_by_fingerprint(self, fingerprint: str) -> Commit | None: | |||||||||
| ).fetchone() | ||||||||||
| if row is None: | ||||||||||
| return None | ||||||||||
| conn.execute( | ||||||||||
| "UPDATE commits SET last_accessed_at = ? WHERE hash = ?", | ||||||||||
| (now_iso, row["hash"]), | ||||||||||
| ) | ||||||||||
| return self._row_to_commit(row) | ||||||||||
|
|
||||||||||
| def find_running_by_fingerprint(self, fingerprint: str) -> Commit | None: | ||||||||||
|
|
||||||||||
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.
The call commit.claimed_at.isoformat() will raise AttributeError if claimed_at is None. While claimed_at is typically set before put_commit, defensive code should verify it is not None to prevent crashes from malformed Commit objects.