Skip to content

Commit 2f9231d

Browse files
committed
simplify
1 parent 818c922 commit 2f9231d

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

routers/common/pagetmpl.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ package common
66
import (
77
goctx "context"
88
"errors"
9+
"sync"
910

1011
activities_model "code.gitea.io/gitea/models/activities"
1112
"code.gitea.io/gitea/models/db"
1213
issues_model "code.gitea.io/gitea/models/issues"
1314
"code.gitea.io/gitea/modules/log"
14-
"code.gitea.io/gitea/modules/util"
1515
"code.gitea.io/gitea/services/context"
1616
)
1717

@@ -69,28 +69,15 @@ type pageHeadNavbarDataType struct {
6969
IsSigned bool
7070
IsSiteAdmin bool
7171

72-
GetNotificationUnreadCount func() int64
73-
cachedNotificationUnreadCount *int64
74-
75-
GetActiveStopwatch func() *StopwatchTmplInfo
76-
cachedActiveStopwatch **StopwatchTmplInfo
72+
GetNotificationUnreadCount func() int64
73+
GetActiveStopwatch func() *StopwatchTmplInfo
7774
}
7875

7976
func PageHeadNavbarData(ctx *context.Context) {
8077
var data pageHeadNavbarDataType
8178
data.IsSigned = ctx.Doer != nil
8279
data.IsSiteAdmin = ctx.Doer != nil && ctx.Doer.IsAdmin
83-
data.GetNotificationUnreadCount = func() int64 {
84-
if data.cachedNotificationUnreadCount == nil {
85-
data.cachedNotificationUnreadCount = util.ToPointer(notificationUnreadCount(ctx))
86-
}
87-
return *data.cachedNotificationUnreadCount
88-
}
89-
data.GetActiveStopwatch = func() *StopwatchTmplInfo {
90-
if data.cachedActiveStopwatch == nil {
91-
data.cachedActiveStopwatch = util.ToPointer(getActiveStopwatch(ctx))
92-
}
93-
return *data.cachedActiveStopwatch
94-
}
80+
data.GetNotificationUnreadCount = sync.OnceValue(func() int64 { return notificationUnreadCount(ctx) })
81+
data.GetActiveStopwatch = sync.OnceValue(func() *StopwatchTmplInfo { return getActiveStopwatch(ctx) })
9582
ctx.Data["HeadNavbarData"] = data
9683
}

0 commit comments

Comments
 (0)