MCPcopy
hub / github.com/safing/portmaster / suggestUsingStaleCacheTask

Function suggestUsingStaleCacheTask

service/resolver/metrics.go:56–140  ·  view source on GitHub ↗
(_ *mgr.WorkerCtx)

Source from the content-addressed store, hash-verified

54var isFirstNotification = true
55
56func suggestUsingStaleCacheTask(_ *mgr.WorkerCtx) error {
57 scheduleNextCall := true
58 switch {
59 case useStaleCache() || useStaleCacheConfigOption.IsSetByUser() || isNotificationSuppressed():
60 // If setting is already active, disable task repeating.
61 scheduleNextCall = false
62
63 // Delete local reference, if used.
64 if suggestUsingStaleCacheNotification != nil {
65 suggestUsingStaleCacheNotification.Delete()
66 suggestUsingStaleCacheNotification = nil
67 }
68
69 case suggestUsingStaleCacheNotification != nil:
70 // Check if notification is already active.
71
72 suggestUsingStaleCacheNotification.Lock()
73 defer suggestUsingStaleCacheNotification.Unlock()
74 if suggestUsingStaleCacheNotification.Meta().IsDeleted() {
75 // Reset local reference if notification was deleted.
76 suggestUsingStaleCacheNotification = nil
77 }
78
79 case getSlowQueriesSensorValue() > 100*time.Millisecond:
80 log.Warningf(
81 "resolver: suggesting user to use stale dns cache with avg query time of %s for config and system resolvers",
82 getSlowQueriesSensorValue().Round(time.Millisecond),
83 )
84
85 const actionSuppressID = "suppress"
86
87 // Notify user.
88 suggestUsingStaleCacheNotification = &notifications.Notification{
89 EventID: "resolver:suggest-using-stale-cache",
90 Type: notifications.Info,
91 Title: "Speed Up Website Loading",
92 Message: "Portmaster has detected that websites may load slower because DNS queries are currently slower than expected. You may want to switch your DNS provider or enable using expired DNS cache entries for better performance.",
93 ShowOnSystem: isFirstNotification && getSlowQueriesSensorValue() > 500*time.Millisecond,
94 Expires: time.Now().Add(10 * time.Minute).Unix(),
95 AvailableActions: []*notifications.Action{
96 {
97 Text: "Open Setting",
98 Type: notifications.ActionTypeOpenSetting,
99 Payload: &notifications.ActionTypeOpenSettingPayload{
100 Key: CfgOptionUseStaleCacheKey,
101 },
102 Visibility: notifications.ActionVisibilityInAppOnly,
103 },
104 {
105 ID: actionSuppressID,
106 Text: "Don't show again",
107 Visibility: notifications.ActionVisibilityDetailed,
108 },
109 {
110 ID: "ack",
111 Text: "Got it!",
112 },
113 },

Callers

nothing calls this directly

Calls 15

WarningfFunction · 0.92
NotifyFunction · 0.92
IsSetByUserMethod · 0.80
IsDeletedMethod · 0.80
SetActionFunctionMethod · 0.80
isNotificationSuppressedFunction · 0.70
suppressNotificationFunction · 0.70
DeleteMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65

Tested by

no test coverage detected