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

When using the TimeZone feature too many sql requests are made #15263

Closed
deanmarcussen opened this issue Feb 7, 2024 · 0 comments · Fixed by #15270
Closed

When using the TimeZone feature too many sql requests are made #15263

deanmarcussen opened this issue Feb 7, 2024 · 0 comments · Fixed by #15270
Labels
Milestone

Comments

@deanmarcussen
Copy link
Member

When using the TimeZone feature, and the user does not have a TimeZone set (which is the default for new users), any requests looking to use ILocalClock will make a database query for the user, fail to find a timezone, and fail to set a cache value.

the issue is in this code

    public async Task<string> GetCurrentUserTimeZoneIdAsync()
        {
            var userName = _httpContextAccessor.HttpContext.User?.Identity?.Name;

            if (string.IsNullOrEmpty(userName))
            {
                return null;
            }

            var key = GetCacheKey(userName);
            var timeZoneId = await _distributedCache.GetStringAsync(key);

            if (string.IsNullOrEmpty(timeZoneId))
            {
                var user = await _userManager.FindByNameAsync(userName) as User;
                timeZoneId = user.As<UserTimeZone>()?.TimeZoneId;

                if (!string.IsNullOrEmpty(timeZoneId))
                {
                    await _distributedCache.SetStringAsync(key, timeZoneId, new DistributedCacheEntryOptions { SlidingExpiration = _slidingExpiration });
                }
            }

            return timeZoneId;
        }

where it might be appropriate to set a NoValueFound cache value, to prevent this.

current workaround is to use user event handlers to force set the usertime zone as they are created to the sites timezone, but this has other issues.

the code above looks like it needs a rework, as it's sliding at one minute, which is a bit low if you're expecting performance.

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 a pull request may close this issue.

2 participants