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

fix(caa dims): separate cache key from full-size URL #518

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

ROpdebee
Copy link
Owner

@ROpdebee ROpdebee commented Jul 5, 2022

In most cases, we can use the full-size URL as the cache key. However, for release groups, the full-size URL is the CAA-redirected front image. When the RG cover is changed, this URL stays the same, so the cache isn't invalidated properly. Also, for PDFs, we were using the derived JP2 URL as the cache key instead of the PDF URL itself. This change fixes both by separating the cache key from the image URL we query. For RGs, the cache key will now be the thumbnail URL, which will change if the RG cover is changed.

Also reworked the tests to do better tests for these URL transformations and extractions. More work is needed there though, I think some of the earlier tests are doing duplicated work. Ideally, the URL transformation and extraction would be split off from the CAAImage class, but I didn't want to go into that much refactoring today.

Unfortunately, the RG image cache won't be shared with the cache of the release images, since RGs use thumbnails as keys while releases use the full-size URL. We could fix this by changing the cache key to something like <release_id>/<image_id> but that would require a DB upgrade to transform existing entries, and would also make the cache specific to CAA/IA URLs. The latter probably isn't too big of a problem though.

https://community.metabrainz.org/t/ropdebees-userscripts-support-thread/551947/92?u=ropdebee

In most cases, we can use the full-size URL as the cache key. However,
for release groups, the full-size URL is the CAA-redirected front image.
When the RG cover is changed, this URL stays the same, so the cache isn't
invalidated properly. Also, for PDFs, we were using the derived JP2 URL as
the cache key instead of the PDF URL itself. This change fixes both by
separating the cache key from the image URL we query. For RGs, the cache key
will now be the thumbnail URL, which will change if the RG cover is changed.

Also reworked the tests to do better tests for these URL transformations and
extractions. More work is needed there though, I think some of the earlier tests
are doing duplicated work. Ideally, the URL transformation and extraction would
be split off from the CAAImage class, but I didn't want to go into that much
refactoring today.

Unfortunately, the RG image cache won't be shared with the cache of the release
images, since RGs use thumbnails as keys while releases use the full-size URL.
We could fix this by changing the cache key to something like <release_id>/<image_id>
but that would require a DB upgrade to transform existing entries, and would also
make the cache specific to CAA/IA URLs. The latter probably isn't too big of a
problem though.
@ROpdebee ROpdebee added bug Something isn't working mb_caa_dimensions labels Jul 5, 2022
@ROpdebee ROpdebee requested a review from kellnerd July 5, 2022 11:40
@codecov
Copy link

codecov bot commented Jul 5, 2022

Codecov Report

Merging #518 (08cc565) into main (e31be17) will increase coverage by 0.08%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #518      +/-   ##
==========================================
+ Coverage   99.68%   99.76%   +0.08%     
==========================================
  Files          56       56              
  Lines        1265     1273       +8     
  Branches      198      200       +2     
==========================================
+ Hits         1261     1270       +9     
  Misses          3        3              
+ Partials        1        0       -1     
Impacted Files Coverage Δ
src/mb_caa_dimensions/Image.ts 100.00% <100.00%> (+1.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e31be17...08cc565. Read the comment docs.

@ROpdebee ROpdebee merged commit af1bf56 into main Jul 27, 2022
@ROpdebee ROpdebee deleted the caa-dims-rg-cache branch July 27, 2022 12:07
@github-actions
Copy link

🚀 Released 2 new userscript version(s):

  • mb_caa_dimensions 2022.7.27.2 in d826d8d
  • mb_enhanced_cover_art_uploads 2022.7.27.2 in 452d25d

github-actions bot added a commit that referenced this pull request Jul 27, 2022
fix(caa dims): separate cache key from full-size URL (#518)
github-actions bot added a commit that referenced this pull request Jul 27, 2022
fix(caa dims): separate cache key from full-size URL (#518)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant