feat(model-updates): filter records without updates in refresh response

Add logic to only include model update records that have actual updates in the refresh response. This improves API efficiency by reducing payload size and only returning relevant data to clients.

The change:
- Adds filtering in ModelUpdateHandler.refresh_model_updates to check has_update method
- Only serializes records that have updates available
- Updates corresponding test to verify filtering behavior

This prevents returning unnecessary data for models that don't have updates available.
This commit is contained in:
Will Miao
2025-10-25 21:31:36 +08:00
parent 427e7a36d5
commit d77b6d78b7
2 changed files with 104 additions and 2 deletions

View File

@@ -1066,10 +1066,16 @@ class ModelUpdateHandler:
self._logger.error("Failed to refresh model updates: %s", exc, exc_info=True)
return web.json_response({"success": False, "error": str(exc)}, status=500)
serialized_records = []
for record in records.values():
has_update_fn = getattr(record, "has_update", None)
if callable(has_update_fn) and has_update_fn():
serialized_records.append(self._serialize_record(record))
return web.json_response(
{
"success": True,
"records": [self._serialize_record(record) for record in records.values()],
"records": serialized_records,
}
)
@@ -1331,4 +1337,3 @@ class ModelHandlerSet:
"get_model_update_status": self.updates.get_model_update_status,
"get_model_versions": self.updates.get_model_versions,
}