Skip to content
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

Merged
merged 2 commits into from
Mar 26, 2024

Conversation

danyx23
Copy link
Contributor

@danyx23 danyx23 commented Mar 20, 2024

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.

@danyx23 danyx23 marked this pull request as ready for review March 20, 2024 20:33
Copy link
Member

@ikesau ikesau left a 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

@danyx23 danyx23 force-pushed the db-autocleanup-for-scripts branch from 1406f03 to b444008 Compare March 21, 2024 22:22
@danyx23 danyx23 force-pushed the db-images-need-rw-transaction branch from 5ae75e6 to 457589a Compare March 21, 2024 22:22
@danyx23 danyx23 force-pushed the db-autocleanup-for-scripts branch from b444008 to 25902dd Compare March 23, 2024 15:34
@danyx23 danyx23 force-pushed the db-images-need-rw-transaction branch from 457589a to 77a8bdb Compare March 23, 2024 15:34
@danyx23 danyx23 force-pushed the db-autocleanup-for-scripts branch from 25902dd to 3631bdb Compare March 25, 2024 11:26
@danyx23 danyx23 force-pushed the db-images-need-rw-transaction branch from 77a8bdb to 3f08c73 Compare March 25, 2024 11:27
@larsyencken
Copy link
Contributor

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/

Copy link
Contributor Author

danyx23 commented Mar 26, 2024

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

@danyx23 danyx23 force-pushed the db-autocleanup-for-scripts branch from 3631bdb to 7dc065f Compare March 26, 2024 11:45
@danyx23 danyx23 force-pushed the db-images-need-rw-transaction branch from 3f08c73 to 12d857b Compare March 26, 2024 11:45
@danyx23 danyx23 force-pushed the db-autocleanup-for-scripts branch from 7dc065f to 77a4d15 Compare March 26, 2024 13:08
@danyx23 danyx23 force-pushed the db-images-need-rw-transaction branch from 12d857b to 02a850c Compare March 26, 2024 13:08
Copy link
Contributor Author

danyx23 commented Mar 26, 2024

Merge activity

  • Mar 26, 10:04 AM EDT: @danyx23 started a stack merge that includes this pull request via Graphite.
  • Mar 26, 10:27 AM EDT: Graphite rebased this pull request as part of a merge.
  • Mar 26, 10:28 AM EDT: @danyx23 merged this pull request with Graphite.

@danyx23 danyx23 force-pushed the db-autocleanup-for-scripts branch from 77a4d15 to cc52aec Compare March 26, 2024 14:25
Base automatically changed from db-autocleanup-for-scripts to master March 26, 2024 14:26
@danyx23 danyx23 force-pushed the db-images-need-rw-transaction branch from 02a850c to 90dc009 Compare March 26, 2024 14:26
@danyx23 danyx23 merged commit 2537c64 into master Mar 26, 2024
17 of 20 checks passed
@danyx23 danyx23 deleted the db-images-need-rw-transaction branch March 26, 2024 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants