Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd2ca62d

Browse files
committed
Simplify telemetry item reporting context handling
1 parentff86e66 commitd2ca62d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

‎site/site.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,10 @@ func ShouldCacheFile(reqFile string) bool {
330330
// reportHTMLFirstServedAt sends a telemetry report when the first HTML is ever served.
331331
// The purpose is to track the first time the first user opens the site.
332332
func (h*Handler)reportHTMLFirstServedAt() {
333-
ctx:=context.Background()
333+
// nolint:gocritic // Manipulating telemetry items is system-restricted.
334+
ctx:=dbauthz.AsSystemRestricted(context.Background())
334335
itemKey:=string(telemetry.TelemetryItemKeyHTMLFirstServedAt)
335-
// nolint:gocritic // Only used for telemetry, so AsSystemRestricted is fine.
336-
_,err:=h.opts.Database.GetTelemetryItem(dbauthz.AsSystemRestricted(ctx),itemKey)
336+
_,err:=h.opts.Database.GetTelemetryItem(ctx,itemKey)
337337
iferr==nil {
338338
// If the value is already set, then we reported it before.
339339
// We don't need to report it again.
@@ -343,16 +343,14 @@ func (h *Handler) reportHTMLFirstServedAt() {
343343
h.opts.Logger.Debug(ctx,"failed to get telemetry html first served at",slog.Error(err))
344344
return
345345
}
346-
// nolint:gocritic // Only used for telemetry, so AsSystemRestricted is fine.
347-
iferr:=h.opts.Database.InsertTelemetryItemIfNotExists(dbauthz.AsSystemRestricted(ctx), database.InsertTelemetryItemIfNotExistsParams{
346+
iferr:=h.opts.Database.InsertTelemetryItemIfNotExists(ctx, database.InsertTelemetryItemIfNotExistsParams{
348347
Key:string(telemetry.TelemetryItemKeyHTMLFirstServedAt),
349348
Value:time.Now().Format(time.RFC3339),
350349
});err!=nil {
351350
h.opts.Logger.Debug(ctx,"failed to set telemetry html first served at",slog.Error(err))
352351
return
353352
}
354-
// nolint:gocritic // Only used for telemetry, so AsSystemRestricted is fine.
355-
item,err:=h.opts.Database.GetTelemetryItem(dbauthz.AsSystemRestricted(ctx),itemKey)
353+
item,err:=h.opts.Database.GetTelemetryItem(ctx,itemKey)
356354
iferr!=nil {
357355
h.opts.Logger.Debug(ctx,"failed to get telemetry html first served at",slog.Error(err))
358356
return

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp