Speed up DownloadEvent queries#370
Conversation
d92ed1d to
a5c7ccf
Compare
This comment has been minimized.
This comment has been minimized.
f3bb23d to
fcfa28d
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
de85df1 to
4776a9d
Compare
|
While we're on it, what do you think about adding mod_id = Column(Integer, ForeignKey('mod.id', ondelete='CASCADE'))
version_id = Column(Integer, ForeignKey('modversion.id', ondelete='CASCADE')) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
eb95326 to
ef59e77
Compare
ef59e77 to
95fcd95
Compare
|
@DasSkelett, what do you think about also removing this SpaceDock/KerbalStuff/common.py Lines 255 to 269 in ebb54cb Sometimes (but not always) the mod page bogs down on If the storage causes |
Hm yeah, that could work. Would also remove a theoretical bug, because a file could be removed inbetween the I'm also pondering about this line: SpaceDock/KerbalStuff/blueprints/mods.py Line 530 in 95fcd95 If we remove* this line, we would not only get rid of another filesystem access, but also allow the reverse proxies to serve this file out of its memory cache even if the storage is inaccessible. *: we still need it for when there's no The next step after these changes should probably be following @techman83's suggestion to store the file size in the database, to get rid of even more calls. |
|
OK, let me know how the latest commit looks, should include those changes. |
fcc8be8 to
92b110e
Compare
0852526 to
a1cabb0
Compare
a1cabb0 to
32b0db2
Compare
DasSkelett
left a comment
There was a problem hiding this comment.
Thanks so much! This looks really really good now, and contains so many improvements. And you kept on implementing every new request I came up with 😄



Problem
Flame graph profiling from #346 has revealed that accessing
DownloadEventis a substantial part of loading a mod page and especially starting a download:Cause
DownloadEventis a big table with a lot of rows, and we filter it by columns that aren't indexed (mod_idandversion_id). This means the database engine has to search every row and check whether they match.Changes
DownloadEvent:(mod_id, created), to be used for loading the mod pageDownloadEvent:(version_id, created), to be used when starting downloadsDownloadEvent.version_idsince if this matches thenDownloadEvent.mod_idwill match as well, and both will now be indexedDownloadEvent.createdand checked whether it was more than 1 hour ago in Python code, but the check was somewhat wrong (it usedtimedelta.seconds, which only goes up to 86399 and so could satisfy the limit when it shouldn't). Now it enforces this limit in SQL, correctly.DownloadEvent.mod_idandDownloadEvent.version_idso download events are deleted from the database if their corresponding mod or version is removedisfileare now removed to lighten the load on storageModVersion.download_sizenow stores the size of the download file, again to lighten the load on storagefeatured.rssroutes no longer set properties on db objects and then calldb.rollback()to undo, because those calls showed up in profiling as slow; the timezone offset is also now included in the RSS output because I think it's supposed to be thereThis should speed up mod page loads and downloads somewhat noticeably in some cases.
Also mypy has changed again, so now we install type libs to satisfy it.