[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 58 return # There are no currently unexpired files 59 59 60 60 # Calculate an expiration date for all existing files 61 - files = session.scalars( 61 + 62 + q = session.scalars( 62 63 sa.select(File) 63 64 .where( 64 - sa.not_(File.removed), 65 - File.sha256.in_(unexpired_files) 65 + sa.not_(File.removed) 66 66 ) 67 67 ) 68 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 + 69 74 for file in files: 70 75 file_path = storage / file.sha256 71 76 stat = os.stat(file_path)