Analytics request loader and game version validation#6064
Open
Analytics request loader and game version validation#6064
Conversation
Member
Pull request changelogAppAddedChangedDeprecatedRemovedFixedSecurityWebsiteAddedChangedDeprecatedRemovedFixedSecurityHostingAddedChangedDeprecatedRemovedFixedSecurity |
fetchfern
requested changes
May 11, 2026
Comment on lines
+26
to
+64
| pub async fn valid_download_tags( | ||
| pool: &PgPool, | ||
| redis: &RedisPool, | ||
| ) -> Result<Arc<DownloadTagsCache>, ApiError> { | ||
| const DOWNLOAD_TAGS_CACHE_TTL: Duration = Duration::from_secs(60 * 5); | ||
|
|
||
| static DOWNLOAD_TAGS_CACHE: ArcSwapOption<DownloadTagsCache> = | ||
| ArcSwapOption::const_empty(); | ||
|
|
||
| let now = Instant::now(); | ||
| let cached = DOWNLOAD_TAGS_CACHE.load(); | ||
| if let Some(cached) = &*cached | ||
| && cached.expires > now | ||
| { | ||
| return Ok(cached.clone()); | ||
| } | ||
|
|
||
| let loaders = Loader::list(pool, redis) | ||
| .await | ||
| .wrap_internal_err("failed to fetch loaders")? | ||
| .into_iter() | ||
| .map(|loader| loader.loader) | ||
| .collect(); | ||
| let game_versions = MinecraftGameVersion::list(None, None, pool, redis) | ||
| .await | ||
| .wrap_internal_err("failed to fetch game versions")? | ||
| .into_iter() | ||
| .map(|game_version| game_version.version) | ||
| .collect(); | ||
|
|
||
| let cache = Arc::new(DownloadTagsCache { | ||
| expires: now + DOWNLOAD_TAGS_CACHE_TTL, | ||
| loaders, | ||
| game_versions, | ||
| }); | ||
| DOWNLOAD_TAGS_CACHE.store(Some(cache.clone())); | ||
|
|
||
| Ok(cache) | ||
| } |
Member
There was a problem hiding this comment.
Would update the cache asynchronously or at least use cache locking through a read/write lock to avoid cache stampede
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.