Skip to content

Fix: prevent bitstream format cache issue by disabling cached version#4212

Merged
tdonohue merged 3 commits intoDSpace:mainfrom
jesielviana:fix-bitstream-unable-to-change-format
Apr 25, 2025
Merged

Fix: prevent bitstream format cache issue by disabling cached version#4212
tdonohue merged 3 commits intoDSpace:mainfrom
jesielviana:fix-bitstream-unable-to-change-format

Conversation

@jesielviana
Copy link
Copy Markdown
Contributor

References

Description

Disable cache to ensure the updated bitstream format is displayed immediately after update.

Instructions for Reviewers

Fixes an issue where bitstream format changes did not appear immediately after saving due to cached data. Cache is now disabled specifically when fetching the bitstream's format to ensure the updated value is shown.

Steps to reproduce the behavior:

  1. Log in as a user with edit item permissions;
  2. Go to my space;
  3. Select a submitted item;
  4. Edit item;
  5. Open bitstream tab;
  6. Click the Edit button.
  7. Change file format.
  8. The newly saved format should be displayed.

List of changes in this PR:

  • Disabled cache when resolving followLink('format') by setting { useCachedVersionIfAvailable: false } in item-edit-bitstream-bundle.component.ts.

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@tdonohue tdonohue added bug performance / caching Related to performance, caching or embedded objects 1 APPROVAL pull request only requires a single approval to merge component: Item (Archived) Item display or editing labels Apr 17, 2025
@tdonohue tdonohue added this to the 9.0 milestone Apr 17, 2025
@tdonohue tdonohue moved this to 🙋 Needs Reviewers Assigned in DSpace 9.0 Release Apr 17, 2025
@tdonohue
Copy link
Copy Markdown
Member

@atarix83 : This PR solves a bug ticket that had been assigned to you last week. Would you be willing to simply review this PR? If it looks good to you too, then we can get this merged quickly & take that ticket off your plate.

@tdonohue tdonohue requested review from atarix83 and tdonohue April 17, 2025 15:14
@FrancescoMolinaro FrancescoMolinaro self-requested a review April 23, 2025 13:36
Copy link
Copy Markdown
Contributor

@FrancescoMolinaro FrancescoMolinaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jesielviana, thanks for the changes and for looking into this!

I agree this is a caching issue, but I believe it would be better to invalidate the cache only for the modified bitstream.
In this way we could still make use of the cache for the unmodified bitstreams.

I think should be enough to add something like
this.requestService.setStaleByHrefSubstring(formatResponse.payload._links.format.href)

or
this.requestService.setStaleByHrefSubstring(formatResponse.payload._links.self.href)

in src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts.

(src/app/core/data/request.service.ts is not currently part of the component's dependencies)

We should be able to handle the cache invalidation in the onSubmit method of the component.

Let me know what you think about it and thanks again for looking into this!

@github-project-automation github-project-automation Bot moved this from 🙋 Needs Reviewers Assigned to 👀 Under Review in DSpace 9.0 Release Apr 23, 2025
@jesielviana
Copy link
Copy Markdown
Contributor Author

Thank you, @FrancescoMolinaro.
I truly believe that the best approach here is to invalidate the cache. I tried to follow your suggestion and added the following line:
this.requestService.setStaleByHrefSubstring(formatResponse.payload._links.format.href);
just above the return formatResponse.payload; statement in the submit method (src/app/bitstream-page/edit-bitstream-page/edit-bitstream-page.component.ts).

However, I couldn’t get it to work as expected.
Would you mind taking a look or helping me figure out what might be going wrong?

Thanks in advance!

@jesielviana
Copy link
Copy Markdown
Contributor Author

I've tried to invalidate the cache in bitstream-data.service.ts by replacing the line with:

this.requestService.setStaleByHrefSubstring(bitstream._links.format.href);

and also tried:

this.requestService.setStaleByHref(bitstream._links.format.href);

However, after updating the format, the new value still doesn’t appear to be reflected in the UI.

@FrancescoMolinaro
Copy link
Copy Markdown
Contributor

FrancescoMolinaro commented Apr 24, 2025

Hi @jesielviana , thanks for looking into it!
You are absolutely right, the solution I proposed in the first place does not work, I might have done some wrong testing, indeed what I suggested is already in act inside the updateFormat method of src/app/core/data/bitstream-data.service.ts but is not working.

I have digged a bit more into the issue and I found out that the object is not cached by href but by request uuid.
So I have adapted the updateFormat method to invalidate also the cache by uuid, in it's subscribe:

`
const bitsreamFormatUrl = bitstream.self + '/format';
this.requestService.removeByHrefSubstring(bitsreamFormatUrl);

// Delete also cache by uuid as the format could be cached also there

this.objectCache.getByHref(bitsreamFormatUrl).pipe(take(1)).subscribe((cachedRequest) => {
const requestUuid = cachedRequest.requestUUIDs[0];
if(this.requestService.hasByUUID(requestUuid)) {
this.requestService.setStaleByUUID(requestUuid);
}
})
`

I tested this in a local environment and seems to be working.
Could you please give it a try?
In case also this should be unsuccessful I'd say the only option left is to invalidate the cache for all the formats in the followlink as you suggested.

Thanks again for looking into it, much appreciated!

@jesielviana
Copy link
Copy Markdown
Contributor Author

Thanks, @FrancescoMolinaro! This works perfectly. I’ve applied your suggestion in the code and pushed the changes. I just replaced the deprecated removeByHrefSubstring method with setStaleByHrefSubstring as recommended.

Really appreciate your help—thanks again!

@tdonohue tdonohue added port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release labels Apr 25, 2025
Copy link
Copy Markdown
Member

@tdonohue tdonohue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thanks @jesielviana & @FrancescoMolinaro ! I tested the updated code today and it's working perfectly. I was also able to verify that this bug exists in 8.x (is reproducible on demo.dspace.org) and also looks to exist in 7.x (code is the same), so I'll port this back to those releases as well.

@github-project-automation github-project-automation Bot moved this from 👀 Under Review to 👍 Reviewer Approved in DSpace 9.0 Release Apr 25, 2025
@tdonohue tdonohue merged commit 353d660 into DSpace:main Apr 25, 2025
15 checks passed
@github-project-automation github-project-automation Bot moved this from 👍 Reviewer Approved to ✅ Done in DSpace 9.0 Release Apr 25, 2025
@dspace-bot
Copy link
Copy Markdown
Contributor

Backport failed for dspace-7_x, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin dspace-7_x
git worktree add -d .worktree/backport-4212-to-dspace-7_x origin/dspace-7_x
cd .worktree/backport-4212-to-dspace-7_x
git switch --create backport-4212-to-dspace-7_x
git cherry-pick -x 600165210190fb1389abe108b0a6e2aea5cfb6b2 4f48f39f7b24903eaea4a639a894520469e4fe95 bb536192c27df34222a3e9ea9532a0b1f1854555

@dspace-bot
Copy link
Copy Markdown
Contributor

Successfully created backport PR for dspace-8_x:

@tdonohue tdonohue removed port to dspace-7_x This PR needs to be ported to `dspace-7_x` branch for next bug-fix release port to dspace-8_x This PR needs to be ported to `dspace-8_x` branch for next bug-fix release labels Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 APPROVAL pull request only requires a single approval to merge bug component: Item (Archived) Item display or editing performance / caching Related to performance, caching or embedded objects

Projects

No open projects
Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

Unable to change bitstream format

4 participants