Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

thumbnail: Log the thumbnail path_id before we start taking the lock.

Alex Vandiverb4013558bb9f
diff --git a/zerver/lib/thumbnail.py b/zerver/lib/thumbnail.py
index 38925a9cb80..db3b2308878 100644
--- a/zerver/lib/thumbnail.py
+++ b/zerver/lib/thumbnail.py
@@ -383,7 +383,7 @@ def maybe_thumbnail(
# enqueued during message rendering; thumbnailing them
# before/during message rendering can cause race
# conditions.
- queue_event_on_commit("thumbnail", {"id": image_row.id})
+ queue_event_on_commit("thumbnail", {"id": image_row.id, "path_id": path_id})
return image_row
except BadImageError:
return None
@@ -463,7 +463,9 @@ def manifest_and_get_user_upload_previews(
# the worker if all of the currently-configured thumbnail
# formats have already been generated.
if enqueue:
- queue_event_on_commit("thumbnail", {"id": image_attachment.id})
+ queue_event_on_commit(
+ "thumbnail", {"id": image_attachment.id, "path_id": image_attachment.path_id}
+ )
else:
url, is_animated = get_default_thumbnail_url(image_attachment)
image_metadata[image_attachment.path_id] = MarkdownImageMetadata(
diff --git a/zerver/management/commands/thumbnail.py b/zerver/management/commands/thumbnail.py
index e6370eac450..ccdeaee294e 100644
--- a/zerver/management/commands/thumbnail.py
+++ b/zerver/management/commands/thumbnail.py
@@ -74,7 +74,10 @@ class Command(ZulipBaseCommand):
if changed:
image_attachment.thumbnail_metadata = found
image_attachment.save(update_fields=["thumbnail_metadata"])
- queue_event_on_commit("thumbnail", {"id": image_attachment.id})
+ queue_event_on_commit(
+ "thumbnail",
+ {"id": image_attachment.id, "path_id": image_attachment.path_id},
+ )
return
for message_class in (Message, ArchivedMessage):
diff --git a/zerver/worker/thumbnail.py b/zerver/worker/thumbnail.py
index d335ede0251..53786bd7192 100644
--- a/zerver/worker/thumbnail.py
+++ b/zerver/worker/thumbnail.py
@@ -33,6 +33,7 @@ class ThumbnailWorker(QueueProcessingWorker):
def consume(self, event: dict[str, Any]) -> None:
start_time = time.perf_counter()
with transaction.atomic(savepoint=False):
+ logger.info("Starting thumbnailing for %s", event.get("path_id", f"id: {event['id']}"))
try:
# This lock prevents us from racing with the on-demand
# rendering that can be triggered if a request is made
@@ -53,7 +54,6 @@ class ThumbnailWorker(QueueProcessingWorker):
)
return
lock_time = time.perf_counter() - start_time
- logger.info("Starting thumbnailing for %s", row.path_id)
result = ensure_thumbnails(row)
commit_time = time.perf_counter()
end_time = time.perf_counter()