Skip to content

Commit

Permalink
Update _to_data_with_mime
Browse files Browse the repository at this point in the history
  • Loading branch information
Marishka17 committed Dec 31, 2024
1 parent 19b5a50 commit 11b9661
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cvat/apps/engine/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,10 +355,17 @@ def _make_frame_context_images_chunk_key(self, db_data: models.Data, frame_numbe
def _to_data_with_mime(self, cache_item: _CacheItem) -> DataWithMime: ...

@overload
def _to_data_with_mime(self, cache_item: Optional[_CacheItem]) -> Optional[DataWithMime]: ...
def _to_data_with_mime(
self, cache_item: Optional[_CacheItem], *, raise_on_null: bool = True
) -> Optional[DataWithMime]: ...

def _to_data_with_mime(self, cache_item: Optional[_CacheItem]) -> Optional[DataWithMime]:
def _to_data_with_mime(
self, cache_item: Optional[_CacheItem], *, raise_on_null: bool = True
) -> Optional[DataWithMime]:
if not cache_item:
if raise_on_null:
raise ValueError("Unexpected null cache item")

return None

return cache_item[:2]
Expand Down Expand Up @@ -387,7 +394,8 @@ def get_task_chunk(
return self._to_data_with_mime(
self._get_cache_item(
key=self._make_chunk_key(db_task, chunk_number, quality=quality),
)
),
raise_on_null=False,
)

def get_or_set_task_chunk(
Expand Down Expand Up @@ -415,7 +423,8 @@ def get_segment_task_chunk(
return self._to_data_with_mime(
self._get_cache_item(
key=self._make_segment_task_chunk_key(db_segment, chunk_number, quality=quality),
)
),
raise_on_null=False,
)

def get_or_set_segment_task_chunk(
Expand Down Expand Up @@ -512,7 +521,9 @@ def remove_context_images_chunks(self, params: Sequence[dict[str, Any]]) -> None
self._bulk_delete_cache_items(keys_to_remove)

def get_cloud_preview(self, db_storage: models.CloudStorage) -> Optional[DataWithMime]:
return self._to_data_with_mime(self._get_cache_item(self._make_preview_key(db_storage)))
return self._to_data_with_mime(
self._get_cache_item(self._make_preview_key(db_storage)), raise_on_null=False
)

def get_or_set_cloud_preview(self, db_storage: models.CloudStorage) -> DataWithMime:
return self._to_data_with_mime(
Expand Down

0 comments on commit 11b9661

Please sign in to comment.