Environment robots lookup is not cached when no setting has been saved, so the database is read on every request
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start in src/Stott.Optimizely.RobotsHandler/Environments/EnvironmentRobotsService.cs and trace how Get handles a missing repository result and how Save clears the cache. Cache a disabled default model for an environment with no saved record, then confirm repeated lookups avoid repository reads and later saves take effect.
Written by the indexing model from the issue text.
Description
Summary
EnvironmentRobotsService.Get(environmentName) only caches the result when the repository returns a record. If no Environment Robots setting has ever been saved for the current environment, EnvironmentRobotsRepository.Get returns null, nothing is cached, and the Dynamic Data Store is queried on every request that passes through RobotsHeaderMiddleware (and MetaRobotsTagHelper).
The admin UI shows each environment with all options unticked whether or not a record exists, so a site that has never used the feature looks correctly configured while running one uncached database read per request.
Affected versions
- Seen in 6.0.2.
- The same code is on
main(src/Stott.Optimizely.RobotsHandler/Environments/EnvironmentRobotsService.cs).
Code
environmentModel = repository.Value.Get(environmentName);
if (environmentModel is not null)
{
cacheHandler.Add(cacheKey, environmentModel);
}
return environmentModel;
Steps to reproduce
- Install the Robots Handler on a site and never save anything on the Environment Robots tab.
- Call
GET /stott.robotshandler/api/environment/listtwice. - Every environment comes back with a different
idon each call (they are generated byIncludeAllEnvironments), which shows no record is stored. - Each page request now runs
EnvironmentRobotsRepository.Getagainst the database, because thenullresult is never cached.
Impact
One small read per request is cheap on its own, but it adds a SQL connection request to every page and API call. We saw this on a DXP Preproduction instance (CMS 12, single instance) during SQL connection pool exhaustion: the sampled stack traces showed the pool timeout raised from RobotsHeaderMiddleware → EnvironmentRobotsRepository.Get on many requests. The add-on was not the root cause of the exhaustion, but the uncached read made it appear on every failing request and added to the connection demand.
Workaround
Save the current environment on the Environment Robots tab with all options unticked. The Save button stays disabled until something changes, so tick and untick an option first. After that, the record exists, is cached for 12 hours, and no X-Robots-Tag header is added.
Suggested fix
When the repository returns null, cache a default model for that environment (all options off, so IsEnabled is false) instead of nothing. The middleware and tag helper already skip a disabled model, so behaviour is unchanged and the cache covers the "never configured" case. Save already calls RemoveAll(), so a later save still takes effect straight away.
- Dominant language
- C#
- Stars
- 3
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from GeekInTheNorth/Stott.Optimizely.RobotsHandler
-
Feature: Robots URL RulesMay be free again @GeekInTheNorth claimed this 158 days ago, and no pull request is open. OpenCMS13 enhancement In Progress
GeekInTheNorth/Stott.Optimizely.RobotsHandler#88 · 1 comment · 1 assignee ·
-
Cosmetic enhancement
Difficulty 4/5 3-5 days Newbie friendliness 35/100
All issues in GeekInTheNorth/Stott.Optimizely.RobotsHandler
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
EricZimmerman/evtx#281 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
philterd/phileas-dotnet#239 ·
Maintainers usually reply within 3 days
-
Note widget: the keyboard covers the editor in landscapePossibly taken @ersinkoc claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ersinkoc/phonebox#1110 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
nkdAgility/azure-devops-migration-tools#3405 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100