feat: improve model update detection logic

Update ModelUpdateRecord.has_update() to only detect updates when a newer remote version exists than the latest local version. Previously, any missing remote version would trigger an update, which could include older versions that shouldn't be considered updates.

- Add logic to find the maximum version ID in library
- Only return True for remote versions newer than the latest local version
- Add comprehensive unit tests for the new update detection behavior
- Update docstring to reflect the new logic
This commit is contained in:
Will Miao
2025-10-25 21:31:01 +08:00
parent c90306cc9b
commit 427e7a36d5
2 changed files with 66 additions and 5 deletions

View File

@@ -63,13 +63,27 @@ class ModelUpdateRecord:
return [version.version_id for version in self.versions if version.is_in_library]
def has_update(self) -> bool:
"""Return True when a non-ignored remote version is missing locally."""
"""Return True when a non-ignored remote version newer than the newest local copy is available."""
if self.should_ignore_model:
return False
return any(
not version.is_in_library and not version.should_ignore for version in self.versions
)
max_in_library = None
for version in self.versions:
if version.is_in_library:
if max_in_library is None or version.version_id > max_in_library:
max_in_library = version.version_id
if max_in_library is None:
return any(
not version.is_in_library and not version.should_ignore for version in self.versions
)
for version in self.versions:
if version.is_in_library or version.should_ignore:
continue
if version.version_id > max_in_library:
return True
return False
class ModelUpdateService: