🔊 Verbose notifying check logging

This commit is contained in:
LittleSheep 2024-11-23 12:16:34 +08:00
parent 720f9690f6
commit 7a2ce20460
2 changed files with 34 additions and 28 deletions

23
.idea/workspace.xml generated
View File

@ -4,9 +4,10 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":boom: Remove deprecated subscription API"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":loud_sound: Verbose notifying logging">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" afterDir="false" /> <change beforePath="$PROJECT_DIR$/pkg/internal/services/notifications.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/notifications.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/services/preferences.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/services/preferences.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -159,7 +160,6 @@
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" /> <option name="CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT" value="false" />
<MESSAGE value=":bug: Trying to fix panic" />
<MESSAGE value=":recycle: Remove most of the dealer deps and move to nexus" /> <MESSAGE value=":recycle: Remove most of the dealer deps and move to nexus" />
<MESSAGE value=":recycle: Refactored more modules into nexus" /> <MESSAGE value=":recycle: Refactored more modules into nexus" />
<MESSAGE value=":recycle: All parts into nexus" /> <MESSAGE value=":recycle: All parts into nexus" />
@ -184,7 +184,8 @@
<MESSAGE value=":sparkles: Allow access user info via numeric id" /> <MESSAGE value=":sparkles: Allow access user info via numeric id" />
<MESSAGE value=":bug: Fix get user info query statement bug" /> <MESSAGE value=":bug: Fix get user info query statement bug" />
<MESSAGE value=":boom: Remove deprecated subscription API" /> <MESSAGE value=":boom: Remove deprecated subscription API" />
<option name="LAST_COMMIT_MESSAGE" value=":boom: Remove deprecated subscription API" /> <MESSAGE value=":loud_sound: Verbose notifying logging" />
<option name="LAST_COMMIT_MESSAGE" value=":loud_sound: Verbose notifying logging" />
<option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" /> <option name="GROUP_MULTIFILE_MERGE_BY_DIRECTORY" value="true" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
@ -199,9 +200,19 @@
<option name="timeStamp" value="1" /> <option name="timeStamp" value="1" />
</line-breakpoint> </line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint"> <line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/pkg/internal/http/api/factors_api.go</url> <url>file://$PROJECT_DIR$/pkg/internal/services/notifications.go</url>
<line>35</line> <line>93</line>
<option name="timeStamp" value="2" /> <option name="timeStamp" value="3" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/pkg/internal/services/notifications.go</url>
<line>73</line>
<option name="timeStamp" value="4" />
</line-breakpoint>
<line-breakpoint enabled="true" type="DlvLineBreakpoint">
<url>file://$PROJECT_DIR$/pkg/internal/services/notifications.go</url>
<line>135</line>
<option name="timeStamp" value="5" />
</line-breakpoint> </line-breakpoint>
</breakpoints> </breakpoints>
</breakpoint-manager> </breakpoint-manager>

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"fmt" "fmt"
"git.solsynth.dev/hypernet/passport/pkg/authkit/models" "git.solsynth.dev/hypernet/passport/pkg/authkit/models"
"github.com/rs/zerolog/log"
"time" "time"
localCache "git.solsynth.dev/hypernet/passport/pkg/internal/cache" localCache "git.solsynth.dev/hypernet/passport/pkg/internal/cache"
@ -122,26 +123,18 @@ func CheckNotificationNotifiable(account models.Account, topic string) bool {
func CheckNotificationNotifiableBatch(accounts []models.Account, topic string) []bool { func CheckNotificationNotifiableBatch(accounts []models.Account, topic string) []bool {
cacheManager := cache.New[any](localCache.S) cacheManager := cache.New[any](localCache.S)
marshal := marshaler.New(cacheManager) marshal := marshaler.New(cacheManager)
contx := context.Background() ctx := context.Background()
var notifiable = make([]bool, len(accounts)) var notifiable = make([]bool, len(accounts))
var queryNeededIdx []uint var queryNeededIdx []uint
notificationMap := make(map[uint]models.PreferenceNotification) notificationMap := make(map[uint]models.PreferenceNotification)
// Check cache for each account // Check cache for each account
for idx, account := range accounts { for _, account := range accounts {
cacheKey := GetNotificationPreferenceCacheKey(account.ID) cacheKey := GetNotificationPreferenceCacheKey(account.ID)
if val, err := marshal.Get(contx, cacheKey, new(models.PreferenceNotification)); err == nil { if val, err := marshal.Get(ctx, cacheKey, new(models.PreferenceNotification)); err == nil {
notification := val.(models.PreferenceNotification) notification := val.(*models.PreferenceNotification)
notificationMap[account.ID] = notification notificationMap[account.ID] = *notification
// Determine if the account is notifiable based on the topic config
if val, ok := notification.Config[topic]; ok {
if status, ok := val.(bool); ok {
notifiable[idx] = status
continue
}
}
notifiable[idx] = true
} else { } else {
// Add to the list of accounts that need to be queried // Add to the list of accounts that need to be queried
queryNeededIdx = append(queryNeededIdx, account.ID) queryNeededIdx = append(queryNeededIdx, account.ID)
@ -163,18 +156,20 @@ func CheckNotificationNotifiableBatch(accounts []models.Account, topic string) [
notificationMap[notification.AccountID] = notification notificationMap[notification.AccountID] = notification
CacheNotificationPreference(notification) // Cache the result CacheNotificationPreference(notification) // Cache the result
} }
}
// Process the notifiable status for the fetched notifications log.Debug().Any("notifiable", notificationMap).Msg("Fetched notifiable status...")
for idx, account := range accounts {
if notification, exists := notificationMap[account.ID]; exists { // Process the notifiable status for the fetched notifications
if val, ok := notification.Config[topic]; ok { for idx, account := range accounts {
if status, ok := val.(bool); ok { if notification, exists := notificationMap[account.ID]; exists {
notifiable[idx] = status if val, ok := notification.Config[topic]; ok {
continue if status, ok := val.(bool); ok {
} notifiable[idx] = status
continue
} }
notifiable[idx] = true
} }
notifiable[idx] = true
} }
} }