Add uncompressed size field to the image storage and add a backfill script (which is not yet automatically called)

This commit is contained in:
Joseph Schorr 2014-09-23 14:01:27 -04:00
parent f6d3238611
commit 86dfca2e3e
5 changed files with 59 additions and 1 deletions

31
tools/uncompressedsize.py Normal file
View file

@ -0,0 +1,31 @@
from data import model
from data.database import ImageStorage
from app import app, storage as store
import logging
def backfill_sizes():
count = ImageStorage.select().where(ImageStorage.uncompressed_size == None).count()
counter = 0
for image_storage in ImageStorage.select().where(ImageStorage.uncompressed_size == None):
logging.debug("Backfilling uncompressed size: %s of %s" % (counter, count))
# Lookup the JSON for the image.
uuid = image_storage.uuid
with_locations = model.get_storage_by_uuid(uuid)
json_data = store.get_content(with_locations.locations, store.image_json_path(uuid))
size = json_data.get('Size', None)
if size is None:
continue
image_storage.uncompressed_size = size
image_storage.save()
counter += 1
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('boto').setLevel(logging.CRITICAL)
backfill_sizes()