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: Add or move progress earlier in loop.

Alex Vandivera9d1adadb7c5
diff --git a/zerver/migrations/0544_copy_avatar_images.py b/zerver/migrations/0544_copy_avatar_images.py
index 607a2d1dcd8..c95b95feda8 100644
--- a/zerver/migrations/0544_copy_avatar_images.py
+++ b/zerver/migrations/0544_copy_avatar_images.py
@@ -60,10 +60,13 @@ def thumbnail_s3_avatars(users: QuerySet[Any]) -> None:
s3={"addressing_style": settings.S3_ADDRESSING_STYLE},
),
).Bucket(settings.S3_AVATAR_BUCKET)
- for user in users:
+ for total_processed, user in enumerate(users):
old_base = os.path.join(str(user.realm_id), old_hash(user))
new_base = os.path.join(str(user.realm_id), new_hash(user))
+ if total_processed % 100 == 0:
+ print(f"Processing {total_processed}/{len(users)} user avatars")
+
try:
old_data = avatar_bucket.Object(old_base + ".original").get()
metadata = old_data["Metadata"]
@@ -108,10 +111,13 @@ def thumbnail_s3_avatars(users: QuerySet[Any]) -> None:
def thumbnail_local_avatars(users: QuerySet[Any]) -> None:
total_processed = 0
assert settings.LOCAL_AVATARS_DIR is not None
- for user in users:
+ for total_processed, user in enumerate(users):
old_base = os.path.join(settings.LOCAL_AVATARS_DIR, str(user.realm_id), old_hash(user))
new_base = os.path.join(settings.LOCAL_AVATARS_DIR, str(user.realm_id), new_hash(user))
+ if total_processed % 100 == 0:
+ print(f"Processing {total_processed}/{len(users)} user avatars")
+
if os.path.exists(new_base + "-medium.png"):
# This user's avatar has already been migrated.
continue
@@ -143,10 +149,6 @@ def thumbnail_local_avatars(users: QuerySet[Any]) -> None:
with open(new_base + "-medium.png", "wb") as f:
f.write(medium)
- total_processed += 1
- if total_processed % 100 == 0:
- print(f"Processed {total_processed}/{len(users)} user avatars")
-
def thumbnail_avatars(apps: StateApps, schema_editor: BaseDatabaseSchemaEditor) -> None:
UserProfile = apps.get_model("zerver", "UserProfile")