Environment robots lookup is not cached when no setting has been saved, so the database is read on every request

オープン 初心者向け
#116 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
backend, databases

調査の方向性

src/Stott.Optimizely.RobotsHandler/Environments/EnvironmentRobotsService.csから始め、Getがリポジトリの結果がない場合をどのように処理するか、またSaveがキャッシュをどのようにクリアするかを追ってください。保存済みレコードがない環境用に無効化されたデフォルトモデルをキャッシュし、繰り返し検索してもリポジトリの読み取りが発生せず、その後の保存が反映されることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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

  1. Install the Robots Handler on a site and never save anything on the Environment Robots tab.
  2. Call GET /stott.robotshandler/api/environment/list twice.
  3. Every environment comes back with a different id on each call (they are generated by IncludeAllEnvironments), which shows no record is stored.
  4. Each page request now runs EnvironmentRobotsRepository.Get against the database, because the null result 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.

主要言語
C#
スター
3
フォーク
5
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

GeekInTheNorth/Stott.Optimizely.RobotsHandler のほかの issue

GeekInTheNorth/Stott.Optimizely.RobotsHandler の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。