Falling back to getting from db and recaching when cache is missing
What does this MR do and why?
Currently the cache can timeout during long imports, this causes issues as the database_id cannot be found anymore.
With this change, if the cache times-out, it will query the database for the id and re-cache it.
If there is no database_id, it caches -1 so avoids further calls to DB and returns nil instead
Screenshots or screen recordings
Screen Recording 2023-10-13 at 2.40.27 PM.mov
How to set up and validate locally
- GitHub import should still work as expected
- Can play around in rails console, Ensure the project you pass in has an issue with iid part of
html_url
attribute (42 in this case).
api_response = {
html_url: 'https://github.com/foo/bar/issues/42',
user: { id: 44, login: 'alice' },
body: 'Hello worlds',
created_at: Time.now + 1.year,
updated_at: Time.now + 1.year,
}
note = Gitlab::GithubImport::Representation::Note.from_api_response(api_response)
finder = Gitlab::GithubImport::IssuableFinder.new(Project.last, note)
# Now using a combination of
# finder.cache_database_id
# Gitlab::Cache::Import::Caching.expire(finder.send(:cache_key), 1.second)
# finder.database_id should return `nil` if issue is missing or cache has -1. Or the issue.id and re-caches it
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #427097 (closed)
Edited by Max Fan