-
-
Notifications
You must be signed in to change notification settings - Fork 229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔨 images need a RW transaction in case they need to update the db 😢 - bubble this up #3385
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Completely brutal 😅
At least, in a way, it's a vindication of all the work you put in - we now can change the transaction signature in a single place and programmatically know all the places it has to be updated.
Just a shame it happened like this 😛
Not sure if it's something that's wrong with my data, but when I try to load the mock site homepage, I get:
TypeError: Cannot read properties of null (reading 'toLocaleDateString')
at formatDate (grapher/packages/@ourworldindata/utils/src/Util.ts:1306:17)
at <anonymous> (grapher/db/model/Gdoc/GdocBase.ts:889:36)
at Array.map (<anonymous>)
at getMinimalGdocPostsByIds (grapher/db/model/Gdoc/GdocBase.ts:883:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at GdocHomepage.loadLinkedDocuments (grapher/db/model/Gdoc/GdocBase.ts:673:13)
at GdocHomepage.loadState (grapher/db/model/Gdoc/GdocBase.ts:823:9)
at loadGdocFromGdocBase (grapher/db/model/Gdoc/GdocFactory.ts:326:5)
at renderFrontPage
1406f03
to
b444008
Compare
5ae75e6
to
457589a
Compare
b444008
to
25902dd
Compare
457589a
to
77a8bdb
Compare
25902dd
to
3631bdb
Compare
77a8bdb
to
3f08c73
Compare
I'm not sure I've understood what's happening here exactly. Is there a side effect happening? E.g. we bake/preview a page, but the process of previewing can refresh/resolve some image data that was not yet resolved/ |
Yeah - the image handling code is written in a way that whenever we are previewing some kind of content via the admin, we collect a list of image resources. If these images are already registered in the images table then it's all good. But if one or more images are not yet registered there then we do a call to the google gdrive api and check if the image exists there. If it does, we copy the image over to r2 and register it in the database. This works but it means that a lot of code that is semantically read only now sometimes wants to write to the database (plus the latency of that request is much higher in those cases). I think we'll probably want to redo our image handling and switch to CF images and a once-a-minute cron job or an on-write-event notification handler on gdrive that sync images to CF images. When we do this, then all the places marked in this PR can revert to only opening a read-only transaction |
3631bdb
to
7dc065f
Compare
3f08c73
to
12d857b
Compare
7dc065f
to
77a4d15
Compare
12d857b
to
02a850c
Compare
77a4d15
to
cc52aec
Compare
02a850c
to
90dc009
Compare
This is not a nice PR - the images code was wrongly tagged as needing only a read-only transaction but it can actually update the DB when a sync occurs. This then bubbled up to a lot of places unfortunately.