aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfusion32 <marcopuzziello@gmail.com>2025-08-08 14:05:38 -0300
committerfusion32 <marcopuzziello@gmail.com>2025-08-08 14:05:38 -0300
commit326793ad5e585e00719252c2bb02bfcd94d518a8 (patch)
tree51ad91a379e11fd57d3248f94fdd9e0b317e15c2
parentd84651a899a6104fce73d95b9c571627c55e5d16 (diff)
downloadweb-326793ad5e585e00719252c2bb02bfcd94d518a8.tar.gz
web-326793ad5e585e00719252c2bb02bfcd94d518a8.zip
refresh account character data
-rw-r--r--main.go8
-rw-r--r--query.go12
2 files changed, 13 insertions, 7 deletions
diff --git a/main.go b/main.go
index 05b6529..3a9d014 100644
--- a/main.go
+++ b/main.go
@@ -98,6 +98,10 @@ func WebKVCallback(Key string, Value string) {
g_QueryManagerPort = ParseInteger(Value)
} else if strings.EqualFold(Key, "QueryManagerPassword") {
g_QueryManagerPassword = ParseString(Value)
+ } else if strings.EqualFold(Key, "MaxCachedAccounts") {
+ g_MaxCachedAccounts = ParseInteger(Value)
+ } else if strings.EqualFold(Key, "MaxCachedCharacters") {
+ g_MaxCachedCharacters = ParseInteger(Value)
} else if strings.EqualFold(Key, "CharacterRefreshInterval") {
g_CharacterRefreshInterval = ParseDuration(Value)
} else if strings.EqualFold(Key, "WorldsRefreshInterval") {
@@ -106,10 +110,6 @@ func WebKVCallback(Key string, Value string) {
g_OnlineCharactersRefreshInterval = ParseDuration(Value)
} else if strings.EqualFold(Key, "KillStatisticsRefreshInterval") {
g_KillStatisticsRefreshInterval = ParseDuration(Value)
- } else if strings.EqualFold(Key, "MaxCachedAccounts") {
- g_MaxCachedAccounts = ParseInteger(Value)
- } else if strings.EqualFold(Key, "MaxCachedCharacters") {
- g_MaxCachedCharacters = ParseInteger(Value)
} else {
g_LogWarn.Printf("Unknown config \"%v\"", Key)
}
diff --git a/query.go b/query.go
index baab921..ef7d253 100644
--- a/query.go
+++ b/query.go
@@ -547,6 +547,15 @@ func GetAccountSummary(AccountID int) (Result int, Account TAccountSummary) {
for Index := 0; Index < len(g_AccountCache); Index += 1 {
Current := &g_AccountCache[Index]
+ // NOTE(fusion): Account data itself shouldn't change over time unless
+ // we do it ourselves, in which case `InvalidateAccountCachedData` is
+ // used to invalidate the cache entry. The problem is that the account
+ // summary also includes character data which will change, depending on
+ // activities on the game server.
+ if time.Since(Current.LastAccess) >= g_CharacterRefreshInterval {
+ *Current = TAccountCacheEntry{}
+ }
+
if Current.LastAccess.Before(LeastRecentlyUsedTime) {
LeastRecentlyUsedIndex = Index
LeastRecentlyUsedTime = Current.LastAccess
@@ -575,9 +584,6 @@ func GetAccountSummary(AccountID int) (Result int, Account TAccountSummary) {
return
}
-// NOTE(fusion): Account data is different from other cached data because it
-// shouldn't change over time unless we do it ourselves, in which case we know
-// exactly when to invalidate cached data.
func InvalidateAccountCachedData(AccountID int) {
g_QueryManagerMutex.Lock()
defer g_QueryManagerMutex.Unlock()