Fix for upserts, question pages (WIP), history #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
So this is a mix of several changes, some are unfinished:
master
instead, but I disabled the links to question pages for now, so it should be ok)Fix for upserts - kinda urgent
I was working on adding foreign keys from
history
toquestions
table when I discovered that fetchers were broken in prod due to the unfortunate combination of: (1) frontpage table is now implemented with foreign keys toquestions
table now; (2) fetched questions are inserted with delete+recreate trick.But foreign keys forbid the questions from being deleted, so deletes failed, and cron job skipped the platform entirely if it had any questions on the frontpage. At least that's what I assume have happened, I haven't checked the full logs.
What's worse is that there's no easy to fix this while keeping the same performance. The only fix I could come up with quickly negates the benefits of #30: in this PR I just delete the questions which don't exist any more, create the new ones and update the ones which existed. But there's no bulk update API in Prisma (or in SQL, actually), so all updates are done in separate SQL queries. Or, to be more precise, in 5 queries per question:
It shouldn't be that bad, though, since our DB is now geographically close to Heroku's instance. And this can be optimized further:
UPDATE ... FROM ...
(but this is impossible with Prisma, so we'll have to drop back to the raw SQL...)On other stuff in this PR: