mirror of
https://git.0x0.st/mia/0x0.git
synced 2025-04-19 14:53:02 +02:00
Coalesce updates to the database during migration
https://git.0x0.st/mia/0x0/pulls/72#issuecomment-226
This commit is contained in:
parent
19d989b696
commit
55ee3740b0
1 changed files with 6 additions and 5 deletions
|
@ -74,16 +74,17 @@ def upgrade():
|
||||||
File.sha256.in_(unexpired_files)
|
File.sha256.in_(unexpired_files)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
updates = [] # We coalesce updates to the database here
|
||||||
for file in files:
|
for file in files:
|
||||||
file_path = storage / file.sha256
|
file_path = storage / file.sha256
|
||||||
stat = os.stat(file_path)
|
stat = os.stat(file_path)
|
||||||
max_age = get_max_lifespan(stat.st_size) # How long the file is allowed to live, in ms
|
max_age = get_max_lifespan(stat.st_size) # How long the file is allowed to live, in ms
|
||||||
file_birth = stat.st_mtime * 1000 # When the file was created, in ms
|
file_birth = stat.st_mtime * 1000 # When the file was created, in ms
|
||||||
op.execute(
|
updates.append({'id': file.id, 'expiration': int(file_birth + max_age)})
|
||||||
sa.update(UpdatedFile)
|
|
||||||
.where(UpdatedFile.c.id == file.id)
|
# Apply coalesced updates
|
||||||
.values({'expiration': int(file_birth + max_age)})
|
session.bulk_update_mappings(File, updates)
|
||||||
)
|
session.commit()
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.drop_column('file', 'expiration')
|
op.drop_column('file', 'expiration')
|
||||||
|
|
Loading…
Add table
Reference in a new issue