Environment robots lookup is not cached when no setting has been saved, so the database is read on every request
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 82/100
Hướng nghiên cứu
Bắt đầu tại src/Stott.Optimizely.RobotsHandler/Environments/EnvironmentRobotsService.cs và theo dõi cách Get xử lý khi không có kết quả từ repository và cách Save xóa cache. Lưu vào cache một model mặc định bị tắt cho môi trường không có bản ghi nào được lưu, sau đó xác nhận rằng các lần tra cứu lặp lại tránh đọc repository và những lần lưu sau đó có hiệu lực.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- C#
- Star
- 3
- Fork
- 5
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của GeekInTheNorth/Stott.Optimizely.RobotsHandler
-
Feature: Robots URL RulesCó thể làm lại được @GeekInTheNorth đã nhận 158 ngày trước và không có pull request nào đang mở. Đang mởCMS13 enhancement In Progress
GeekInTheNorth/Stott.Optimizely.RobotsHandler#88 · 1 bình luận · 1 người được giao ·
-
Cosmetic enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
Tất cả issue của GeekInTheNorth/Stott.Optimizely.RobotsHandler
Issue tương tự
-
effort:S P3
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
nightscout/nocturne#4930 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
reactiveui/ReactiveUI#4589 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 91/100
reactiveui/Akavache#1278 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FOODPLANNER Subtask
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
aau-giraf/foodplanner-api#314 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
juandresrodca/AdminForge#70 ·
Maintainer thường phản hồi trong vòng 1 ngày