@@ -6,12 +6,12 @@ package common
66import (
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
7976func 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