Environment robots lookup is not cached when no setting has been saved, so the database is read on every request
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
Direzione di ricerca
Inizia da src/Stott.Optimizely.RobotsHandler/Environments/EnvironmentRobotsService.cs e segui come Get gestisce un risultato mancante del repository e come Save svuota la cache. Memorizza nella cache un modello predefinito disabilitato per un ambiente senza record salvati, poi conferma che le ricerche ripetute evitano letture dal repository e che i salvataggi successivi hanno effetto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- C#
- Stelle
- 3
- Fork
- 5
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di GeekInTheNorth/Stott.Optimizely.RobotsHandler
-
Feature: Robots URL RulesForse di nuovo libera @GeekInTheNorth l’ha presa 158 giorni fa e non c’è nessuna pull request aperta. ApertaCMS13 enhancement In Progress
GeekInTheNorth/Stott.Optimizely.RobotsHandler#88 · 1 commento · 1 assegnatario ·
-
Cosmetic enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
Tutte le issue di GeekInTheNorth/Stott.Optimizely.RobotsHandler
Issue simili
-
effort:S P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
nightscout/nocturne#4930 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
reactiveui/ReactiveUI#4589 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 91/100
reactiveui/Akavache#1278 ·
I maintainer di solito rispondono entro 1 giorno
-
FOODPLANNER Subtask
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
aau-giraf/foodplanner-api#314 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
juandresrodca/AdminForge#70 ·
I maintainer di solito rispondono entro 1 giorno