feat: implement same_base update strategy for model annotations

Add support for configurable update flag strategy with new "same_base" mode that considers base model versions when determining update availability. The strategy is controlled by the "update_flag_strategy" setting.

When strategy is set to "same_base":
- Uses get_records_bulk instead of has_updates_bulk
- Compares model versions against highest local versions per base model
- Provides more granular update detection based on base model relationships

Fallback to existing bulk or individual update checks when:
- Strategy is not "same_base"
- Bulk operations fail
- Records are unavailable

This enables more precise update flagging for models sharing common bases.
This commit is contained in:
Will Miao
2025-11-17 19:26:41 +08:00
parent 8158441a92
commit 0e73db0669
5 changed files with 458 additions and 48 deletions

View File

@@ -52,11 +52,11 @@ class NotFoundProvider:
return {}
def make_version(version_id, *, in_library, should_ignore=False):
def make_version(version_id, *, in_library, base_model=None, should_ignore=False):
return ModelVersionRecord(
version_id=version_id,
name=None,
base_model=None,
base_model=base_model,
released_at=None,
size_bytes=None,
preview_url=None,
@@ -147,6 +147,25 @@ def test_has_update_detects_newer_remote_version():
assert record.has_update() is True
def test_has_update_for_base_matches_same_base_model():
record = make_record(
make_version(5, in_library=True, base_model="Pony"),
make_version(6, in_library=False, base_model="Pony"),
make_version(7, in_library=False, base_model="Flux.1"),
)
assert record.has_update_for_base(5, "Pony") is True
def test_has_update_for_base_rejects_other_base_models():
record = make_record(
make_version(10, in_library=True, base_model="Flux"),
make_version(20, in_library=False, base_model="SDXL"),
)
assert record.has_update_for_base(10, "Flux") is False
@pytest.mark.asyncio
async def test_refresh_persists_versions_and_uses_cache(tmp_path):
db_path = tmp_path / "updates.sqlite"