[mirror of https://git.0x0.st/mia/0x0] No-bullshit file hosting and URL shortening service https://0x0.st

migrations: Fix file expirations on SQLite

Well that was what we feared. I love arbitrary hardcoded limits.

+8 -3
+8 -3
migrations/versions/939a08e1d6e5_.py
··· 58 return # There are no currently unexpired files 59 60 # Calculate an expiration date for all existing files 61 - files = session.scalars( 62 sa.select(File) 63 .where( 64 - sa.not_(File.removed), 65 - File.sha256.in_(unexpired_files) 66 ) 67 ) 68 updates = [] # We coalesce updates to the database here 69 for file in files: 70 file_path = storage / file.sha256 71 stat = os.stat(file_path)
··· 58 return # There are no currently unexpired files 59 60 # Calculate an expiration date for all existing files 61 + 62 + q = session.scalars( 63 sa.select(File) 64 .where( 65 + sa.not_(File.removed) 66 ) 67 ) 68 updates = [] # We coalesce updates to the database here 69 + 70 + # SQLite has a hard limit on the number of variables so we 71 + # need to do this the slow way 72 + files = [f for f in q if f.sha256 in unexpired_files] 73 + 74 for file in files: 75 file_path = storage / file.sha256 76 stat = os.stat(file_path)