mirror of
https://git.0x0.st/mia/0x0.git
synced 2025-04-19 14:53:02 +02:00
More efficiently filter to unexpired files when migrating
https://git.0x0.st/mia/0x0/pulls/72#issuecomment-224
This commit is contained in:
parent
74b6f986ee
commit
19d989b696
1 changed files with 12 additions and 12 deletions
|
@ -62,7 +62,7 @@ def upgrade():
|
||||||
# List of file hashes which have not expired yet
|
# List of file hashes which have not expired yet
|
||||||
# This could get really big for some servers
|
# This could get really big for some servers
|
||||||
try:
|
try:
|
||||||
unexpired_files = set(os.listdir(storage))
|
unexpired_files = os.listdir(storage)
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
return # There are no currently unexpired files
|
return # There are no currently unexpired files
|
||||||
|
|
||||||
|
@ -70,11 +70,11 @@ def upgrade():
|
||||||
files = session.scalars(
|
files = session.scalars(
|
||||||
sa.select(File)
|
sa.select(File)
|
||||||
.where(
|
.where(
|
||||||
sa.not_(File.removed)
|
sa.not_(File.removed),
|
||||||
|
File.sha256.in_(unexpired_files)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.sha256 in unexpired_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
|
||||||
|
|
Loading…
Add table
Reference in a new issue