fix(api): never cache anchor=latest windows as immutable [CI]
This commit is contained in:
1 parent
fb9dc155f5
commit
b33e50696d
2 files changed
+8
-1
No files matched your search
@@ -32,7 +32,10 @@ internal static class QueryHelpers
|
||||
/// </summary>
|
||||
public static IResult? ApplyCaching(HttpContext http, QueryRange range, long nowMs, string material)
|
||||
{
|
||||
bool closed = !range.IsRelative && range.RequestedToMs < nowMs - (2 * Steps.Minute);
|
||||
// anchor=latest 的相对时间段会被换成以“最后一个样本”为终点的绝对区间:线路停过一阵再恢复时,同一个地址的内容就会变,
|
||||
// 不能当成“已经结束的区间”永久缓存(浏览器会把某一刻的旧数据一直留着,页面上就是线路条不更新)。
|
||||
bool anchored = string.Equals(http.Request.Query["anchor"], "latest", StringComparison.OrdinalIgnoreCase);
|
||||
bool closed = !anchored && !range.IsRelative && range.RequestedToMs < nowMs - (2 * Steps.Minute);
|
||||
if (!closed)
|
||||
{
|
||||
http.Response.Headers.CacheControl = "no-store";
|
||||
|
||||
@@ -96,6 +96,10 @@ public sealed class IngestAndQueryTests : IClassFixture<BackendFixture>
|
||||
Assert.Equal(600, anchored["summary"]!["samples"]!["udp_echo"]!.GetValue<long>());
|
||||
Assert.False(anchored["live"]!.GetValue<bool>());
|
||||
|
||||
// 这个窗口是以“最后一个样本”为终点的绝对区间,但线路恢复之后同一个地址的内容就变了:不能被浏览器永久缓存
|
||||
using HttpResponseMessage raw = await _backend.Admin.GetAsync($"/api/public/lines/{_backend.Line(id)}/series?range=5m&step=10s&metrics=loss.total&anchor=latest");
|
||||
Assert.Equal("no-store", raw.Headers.CacheControl!.ToString());
|
||||
|
||||
// anchor=now is the default behaviour; anything else is rejected
|
||||
JsonNode explicitNow = await SeriesAsync(id, "range=5m&step=10s&metrics=loss.total&anchor=now");
|
||||
Assert.Null(explicitNow["summary"]!["samples"]!["udp_echo"]);
|
||||
|
||||
Reference in new issue
Block a user