From 9196e9674876849a5e0b508f9208a5c35354da77 Mon Sep 17 00:00:00 2001 From: man90 Date: Tue, 19 May 2026 19:11:31 +0200 Subject: [PATCH 1/5] Implement saving time elapsed and client id in Redis cache --- cache/cache.go | 20 ++++++++++++-------- cache/cache_test.go | 14 +++++++------- scraper/scrapeAdventurer.go | 5 ++++- scraper/scrapeAdventurerSearch.go | 5 ++++- scraper/scrapeGuild.go | 5 ++++- scraper/scrapeGuildSearch.go | 5 ++++- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 6e922c8..c0e9f51 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -14,13 +14,15 @@ import ( ) type CacheEntry[T any] struct { - Data T `json:"data"` - Date time.Time `json:"date"` - Status int `json:"status"` + ClientID string `json:"clientId,omitempty"` + Data T `json:"data"` + Date time.Time `json:"date"` + Status int `json:"status"` + TimeElapsed time.Duration `json:"timeElapsed,omitempty"` } type Cache[T any] interface { - AddRecord(keys []string, data T, status int, taskId string) (date string, expires string) + AddRecord(keys []string, data T, status int, taskId, clientID string, timeElapsed time.Duration) (date string, expires string) GetRecord(keys []string) (data T, status int, date string, expires string, found bool) GetItemCount() int GetKeys() []string @@ -47,11 +49,13 @@ func newRedisCache[T any](client *redis.Client, namespace string) *redisCache[T] } } -func (c *redisCache[T]) AddRecord(keys []string, data T, status int, taskId string) (date, expires string) { +func (c *redisCache[T]) AddRecord(keys []string, data T, status int, taskId, clientID string, timeElapsed time.Duration) (date, expires string) { entry := CacheEntry[T]{ - Data: data, - Date: time.Now(), - Status: status, + ClientID: clientID, + Data: data, + Date: time.Now(), + Status: status, + TimeElapsed: timeElapsed, } b, _ := json.Marshal(entry) diff --git a/cache/cache_test.go b/cache/cache_test.go index ea44a91..b66a5ca 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -47,7 +47,7 @@ func TestRedisCacheAddAndGetRecord(t *testing.T) { keys := []string{"key1", "key2"} status := 200 - _, _ = c.AddRecord(keys, data, status, "task123") + _, _ = c.AddRecord(keys, data, status, "task123", "client456", time.Millisecond*500) gotData, gotStatus, _, _, found := c.GetRecord(keys) if !found { @@ -79,8 +79,8 @@ func TestRedisCacheItemCount(t *testing.T) { t.Fatal("Expected empty cache") } - c.AddRecord([]string{"a"}, testStruct{"x"}, 200, "task1") - c.AddRecord([]string{"b"}, testStruct{"y"}, 200, "task2") + c.AddRecord([]string{"a"}, testStruct{"x"}, 200, "task1", "client1", time.Millisecond*100) + c.AddRecord([]string{"b"}, testStruct{"y"}, 200, "task2", "client2", time.Millisecond*100) if c.GetItemCount() != 2 { t.Fatalf("Expected 2 items, got %d", c.GetItemCount()) @@ -90,8 +90,8 @@ func TestRedisCacheItemCount(t *testing.T) { func TestRedisCacheGetKeys(t *testing.T) { c := getTestRedisCache[testStruct](t, "test_keys") - c.AddRecord([]string{"k1"}, testStruct{"v1"}, 200, "task1") - c.AddRecord([]string{"k2"}, testStruct{"v2"}, 200, "task2") + c.AddRecord([]string{"k1"}, testStruct{"v1"}, 200, "task1", "client1", time.Millisecond*100) + c.AddRecord([]string{"k2"}, testStruct{"v2"}, 200, "task2", "client2", time.Millisecond*100) keys := c.GetKeys() @@ -118,8 +118,8 @@ func TestRedisCacheGetKeys(t *testing.T) { func TestRedisCacheGetValues(t *testing.T) { c := getTestRedisCache[testStruct](t, "test_values") - c.AddRecord([]string{"a"}, testStruct{"aaa"}, 200, "task1") - c.AddRecord([]string{"b"}, testStruct{"bbb"}, 200, "task2") + c.AddRecord([]string{"a"}, testStruct{"aaa"}, 200, "task1", "client1", time.Millisecond*100) + c.AddRecord([]string{"b"}, testStruct{"bbb"}, 200, "task2", "client2", time.Millisecond*100) values := c.GetValues() diff --git a/scraper/scrapeAdventurer.go b/scraper/scrapeAdventurer.go index 6c2cfba..92a2873 100644 --- a/scraper/scrapeAdventurer.go +++ b/scraper/scrapeAdventurer.go @@ -6,6 +6,7 @@ import ( "regexp" "strconv" "strings" + "time" "github.com/gocolly/colly/v2" @@ -234,5 +235,7 @@ func scrapeAdventurer(body *colly.HTMLElement, region, profileTarget string) { profile.CombatFame = utils.CalculateCombatFame(profile.Characters) } - cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskId")) + parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + elapsed := time.Since(parsedStartTime) + cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) } diff --git a/scraper/scrapeAdventurerSearch.go b/scraper/scrapeAdventurerSearch.go index 090597e..737c08f 100644 --- a/scraper/scrapeAdventurerSearch.go +++ b/scraper/scrapeAdventurerSearch.go @@ -3,6 +3,7 @@ package scraper import ( "net/http" "strconv" + "time" "github.com/gocolly/colly/v2" @@ -51,5 +52,7 @@ func scrapeAdventurerSearch(body *colly.HTMLElement, region, query, searchType s profiles = append(profiles, profile) }) - cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskId")) + parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + elapsed := time.Since(parsedStartTime) + cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) } diff --git a/scraper/scrapeGuild.go b/scraper/scrapeGuild.go index 5ce4145..0fad605 100644 --- a/scraper/scrapeGuild.go +++ b/scraper/scrapeGuild.go @@ -5,6 +5,7 @@ import ( "slices" "strconv" "strings" + "time" "github.com/gocolly/colly/v2" @@ -74,5 +75,7 @@ func scrapeGuild(body *colly.HTMLElement, region, guildName string) { } } - cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId")) + parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + elapsed := time.Since(parsedStartTime) + cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) } diff --git a/scraper/scrapeGuildSearch.go b/scraper/scrapeGuildSearch.go index 9f68b98..4801f16 100644 --- a/scraper/scrapeGuildSearch.go +++ b/scraper/scrapeGuildSearch.go @@ -3,6 +3,7 @@ package scraper import ( "net/http" "strconv" + "time" "github.com/gocolly/colly/v2" @@ -37,5 +38,7 @@ func scrapeGuildSearch(body *colly.HTMLElement, region, query string) { guildProfiles = append(guildProfiles, guildProfile) }) - cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskId")) + parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + elapsed := time.Since(parsedStartTime) + cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) } From be181b6398d534a88c1b85e170a80659899fd0bc Mon Sep 17 00:00:00 2001 From: man90 Date: Wed, 20 May 2026 10:31:22 +0200 Subject: [PATCH 2/5] Add instanceId to Redis cache entries --- cache/cache.go | 8 +++++--- cache/cache_test.go | 14 +++++++------- scraper/scrapeAdventurer.go | 5 ++--- scraper/scrapeAdventurerSearch.go | 5 ++--- scraper/scrapeGuild.go | 5 ++--- scraper/scrapeGuildSearch.go | 5 ++--- 6 files changed, 20 insertions(+), 22 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index c0e9f51..624935b 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -17,12 +17,13 @@ type CacheEntry[T any] struct { ClientID string `json:"clientId,omitempty"` Data T `json:"data"` Date time.Time `json:"date"` + InstanceID string `json:"instanceId,omitempty"` Status int `json:"status"` TimeElapsed time.Duration `json:"timeElapsed,omitempty"` } type Cache[T any] interface { - AddRecord(keys []string, data T, status int, taskId, clientID string, timeElapsed time.Duration) (date string, expires string) + AddRecord(keys []string, data T, status int, taskId, clientID string, startTime time.Time) (date string, expires string) GetRecord(keys []string) (data T, status int, date string, expires string, found bool) GetItemCount() int GetKeys() []string @@ -49,13 +50,14 @@ func newRedisCache[T any](client *redis.Client, namespace string) *redisCache[T] } } -func (c *redisCache[T]) AddRecord(keys []string, data T, status int, taskId, clientID string, timeElapsed time.Duration) (date, expires string) { +func (c *redisCache[T]) AddRecord(keys []string, data T, status int, taskId, clientID string, startTime time.Time) (date, expires string) { entry := CacheEntry[T]{ ClientID: clientID, Data: data, Date: time.Now(), + InstanceID: viper.GetString("instanceid"), Status: status, - TimeElapsed: timeElapsed, + TimeElapsed: time.Since(startTime), } b, _ := json.Marshal(entry) diff --git a/cache/cache_test.go b/cache/cache_test.go index b66a5ca..312e353 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -47,7 +47,7 @@ func TestRedisCacheAddAndGetRecord(t *testing.T) { keys := []string{"key1", "key2"} status := 200 - _, _ = c.AddRecord(keys, data, status, "task123", "client456", time.Millisecond*500) + _, _ = c.AddRecord(keys, data, status, "task123", "client456", time.Now().Add(-time.Second*10)) gotData, gotStatus, _, _, found := c.GetRecord(keys) if !found { @@ -79,8 +79,8 @@ func TestRedisCacheItemCount(t *testing.T) { t.Fatal("Expected empty cache") } - c.AddRecord([]string{"a"}, testStruct{"x"}, 200, "task1", "client1", time.Millisecond*100) - c.AddRecord([]string{"b"}, testStruct{"y"}, 200, "task2", "client2", time.Millisecond*100) + c.AddRecord([]string{"a"}, testStruct{"x"}, 200, "task1", "client1", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"b"}, testStruct{"y"}, 200, "task2", "client2", time.Now().Add(-time.Second*10)) if c.GetItemCount() != 2 { t.Fatalf("Expected 2 items, got %d", c.GetItemCount()) @@ -90,8 +90,8 @@ func TestRedisCacheItemCount(t *testing.T) { func TestRedisCacheGetKeys(t *testing.T) { c := getTestRedisCache[testStruct](t, "test_keys") - c.AddRecord([]string{"k1"}, testStruct{"v1"}, 200, "task1", "client1", time.Millisecond*100) - c.AddRecord([]string{"k2"}, testStruct{"v2"}, 200, "task2", "client2", time.Millisecond*100) + c.AddRecord([]string{"k1"}, testStruct{"v1"}, 200, "task1", "client1", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"k2"}, testStruct{"v2"}, 200, "task2", "client2", time.Now().Add(-time.Second*10)) keys := c.GetKeys() @@ -118,8 +118,8 @@ func TestRedisCacheGetKeys(t *testing.T) { func TestRedisCacheGetValues(t *testing.T) { c := getTestRedisCache[testStruct](t, "test_values") - c.AddRecord([]string{"a"}, testStruct{"aaa"}, 200, "task1", "client1", time.Millisecond*100) - c.AddRecord([]string{"b"}, testStruct{"bbb"}, 200, "task2", "client2", time.Millisecond*100) + c.AddRecord([]string{"a"}, testStruct{"aaa"}, 200, "task1", "client1", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"b"}, testStruct{"bbb"}, 200, "task2", "client2", time.Now().Add(-time.Second*10)) values := c.GetValues() diff --git a/scraper/scrapeAdventurer.go b/scraper/scrapeAdventurer.go index 92a2873..60965c3 100644 --- a/scraper/scrapeAdventurer.go +++ b/scraper/scrapeAdventurer.go @@ -235,7 +235,6 @@ func scrapeAdventurer(body *colly.HTMLElement, region, profileTarget string) { profile.CombatFame = utils.CalculateCombatFame(profile.Characters) } - parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - elapsed := time.Since(parsedStartTime) - cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) + startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) } diff --git a/scraper/scrapeAdventurerSearch.go b/scraper/scrapeAdventurerSearch.go index 737c08f..eba7d71 100644 --- a/scraper/scrapeAdventurerSearch.go +++ b/scraper/scrapeAdventurerSearch.go @@ -52,7 +52,6 @@ func scrapeAdventurerSearch(body *colly.HTMLElement, region, query, searchType s profiles = append(profiles, profile) }) - parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - elapsed := time.Since(parsedStartTime) - cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) + startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) } diff --git a/scraper/scrapeGuild.go b/scraper/scrapeGuild.go index 0fad605..9a9e17c 100644 --- a/scraper/scrapeGuild.go +++ b/scraper/scrapeGuild.go @@ -75,7 +75,6 @@ func scrapeGuild(body *colly.HTMLElement, region, guildName string) { } } - parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - elapsed := time.Since(parsedStartTime) - cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) + startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) } diff --git a/scraper/scrapeGuildSearch.go b/scraper/scrapeGuildSearch.go index 4801f16..e57557f 100644 --- a/scraper/scrapeGuildSearch.go +++ b/scraper/scrapeGuildSearch.go @@ -38,7 +38,6 @@ func scrapeGuildSearch(body *colly.HTMLElement, region, query string) { guildProfiles = append(guildProfiles, guildProfile) }) - parsedStartTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - elapsed := time.Since(parsedStartTime) - cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), elapsed) + startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) + cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) } From 1ff2051e1fac75d90a14c89bc0e21728ff6509de Mon Sep 17 00:00:00 2001 From: man90 Date: Thu, 21 May 2026 21:39:34 +0200 Subject: [PATCH 3/5] Remove unused parameter --- cache/cache.go | 4 ++-- cache/cache_test.go | 14 +++++++------- scraper/scrapeAdventurer.go | 2 +- scraper/scrapeAdventurerSearch.go | 2 +- scraper/scrapeGuild.go | 2 +- scraper/scrapeGuildSearch.go | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 624935b..7d7024f 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -23,7 +23,7 @@ type CacheEntry[T any] struct { } type Cache[T any] interface { - AddRecord(keys []string, data T, status int, taskId, clientID string, startTime time.Time) (date string, expires string) + AddRecord(keys []string, data T, status int, clientID string, startTime time.Time) (date string, expires string) GetRecord(keys []string) (data T, status int, date string, expires string, found bool) GetItemCount() int GetKeys() []string @@ -50,7 +50,7 @@ func newRedisCache[T any](client *redis.Client, namespace string) *redisCache[T] } } -func (c *redisCache[T]) AddRecord(keys []string, data T, status int, taskId, clientID string, startTime time.Time) (date, expires string) { +func (c *redisCache[T]) AddRecord(keys []string, data T, status int, clientID string, startTime time.Time) (date, expires string) { entry := CacheEntry[T]{ ClientID: clientID, Data: data, diff --git a/cache/cache_test.go b/cache/cache_test.go index 312e353..188bd09 100644 --- a/cache/cache_test.go +++ b/cache/cache_test.go @@ -47,7 +47,7 @@ func TestRedisCacheAddAndGetRecord(t *testing.T) { keys := []string{"key1", "key2"} status := 200 - _, _ = c.AddRecord(keys, data, status, "task123", "client456", time.Now().Add(-time.Second*10)) + _, _ = c.AddRecord(keys, data, status, "client456", time.Now().Add(-time.Second*10)) gotData, gotStatus, _, _, found := c.GetRecord(keys) if !found { @@ -79,8 +79,8 @@ func TestRedisCacheItemCount(t *testing.T) { t.Fatal("Expected empty cache") } - c.AddRecord([]string{"a"}, testStruct{"x"}, 200, "task1", "client1", time.Now().Add(-time.Second*10)) - c.AddRecord([]string{"b"}, testStruct{"y"}, 200, "task2", "client2", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"a"}, testStruct{"x"}, 200, "client1", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"b"}, testStruct{"y"}, 200, "client2", time.Now().Add(-time.Second*10)) if c.GetItemCount() != 2 { t.Fatalf("Expected 2 items, got %d", c.GetItemCount()) @@ -90,8 +90,8 @@ func TestRedisCacheItemCount(t *testing.T) { func TestRedisCacheGetKeys(t *testing.T) { c := getTestRedisCache[testStruct](t, "test_keys") - c.AddRecord([]string{"k1"}, testStruct{"v1"}, 200, "task1", "client1", time.Now().Add(-time.Second*10)) - c.AddRecord([]string{"k2"}, testStruct{"v2"}, 200, "task2", "client2", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"k1"}, testStruct{"v1"}, 200, "client1", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"k2"}, testStruct{"v2"}, 200, "client2", time.Now().Add(-time.Second*10)) keys := c.GetKeys() @@ -118,8 +118,8 @@ func TestRedisCacheGetKeys(t *testing.T) { func TestRedisCacheGetValues(t *testing.T) { c := getTestRedisCache[testStruct](t, "test_values") - c.AddRecord([]string{"a"}, testStruct{"aaa"}, 200, "task1", "client1", time.Now().Add(-time.Second*10)) - c.AddRecord([]string{"b"}, testStruct{"bbb"}, 200, "task2", "client2", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"a"}, testStruct{"aaa"}, 200, "client1", time.Now().Add(-time.Second*10)) + c.AddRecord([]string{"b"}, testStruct{"bbb"}, 200, "client2", time.Now().Add(-time.Second*10)) values := c.GetValues() diff --git a/scraper/scrapeAdventurer.go b/scraper/scrapeAdventurer.go index 60965c3..2b06fca 100644 --- a/scraper/scrapeAdventurer.go +++ b/scraper/scrapeAdventurer.go @@ -236,5 +236,5 @@ func scrapeAdventurer(body *colly.HTMLElement, region, profileTarget string) { } startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) + cache.Profiles.AddRecord([]string{region, profileTarget}, profile, status, body.Request.Ctx.Get("taskClient"), startTime) } diff --git a/scraper/scrapeAdventurerSearch.go b/scraper/scrapeAdventurerSearch.go index eba7d71..c0b0e52 100644 --- a/scraper/scrapeAdventurerSearch.go +++ b/scraper/scrapeAdventurerSearch.go @@ -53,5 +53,5 @@ func scrapeAdventurerSearch(body *colly.HTMLElement, region, query, searchType s }) startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) + cache.ProfileSearch.AddRecord([]string{region, query, searchType}, profiles, status, body.Request.Ctx.Get("taskClient"), startTime) } diff --git a/scraper/scrapeGuild.go b/scraper/scrapeGuild.go index 9a9e17c..5e2fef7 100644 --- a/scraper/scrapeGuild.go +++ b/scraper/scrapeGuild.go @@ -76,5 +76,5 @@ func scrapeGuild(body *colly.HTMLElement, region, guildName string) { } startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) + cache.GuildProfiles.AddRecord([]string{region, guildName}, guildProfile, status, body.Request.Ctx.Get("taskClient"), startTime) } diff --git a/scraper/scrapeGuildSearch.go b/scraper/scrapeGuildSearch.go index e57557f..ff6ec28 100644 --- a/scraper/scrapeGuildSearch.go +++ b/scraper/scrapeGuildSearch.go @@ -39,5 +39,5 @@ func scrapeGuildSearch(body *colly.HTMLElement, region, query string) { }) startTime, _ := time.Parse(time.RFC3339, body.Request.Ctx.Get("taskAddedAt")) - cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskId"), body.Request.Ctx.Get("taskClient"), startTime) + cache.GuildSearch.AddRecord([]string{region, query}, guildProfiles, status, body.Request.Ctx.Get("taskClient"), startTime) } From 7fd8d8b8010dcd763f7f06a7def3c8f836f0f2cf Mon Sep 17 00:00:00 2001 From: man90 Date: Fri, 22 May 2026 10:53:37 +0200 Subject: [PATCH 4/5] Convert timeElapsed property to milliseconds --- cache/cache.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 7d7024f..dc81b0e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -14,12 +14,12 @@ import ( ) type CacheEntry[T any] struct { - ClientID string `json:"clientId,omitempty"` - Data T `json:"data"` - Date time.Time `json:"date"` - InstanceID string `json:"instanceId,omitempty"` - Status int `json:"status"` - TimeElapsed time.Duration `json:"timeElapsed,omitempty"` + ClientID string `json:"clientId,omitempty"` + Data T `json:"data"` + Date time.Time `json:"date"` + InstanceID string `json:"instanceId,omitempty"` + Status int `json:"status"` + TimeElapsed int `json:"timeElapsed,omitempty"` } type Cache[T any] interface { @@ -57,7 +57,7 @@ func (c *redisCache[T]) AddRecord(keys []string, data T, status int, clientID st Date: time.Now(), InstanceID: viper.GetString("instanceid"), Status: status, - TimeElapsed: time.Since(startTime), + TimeElapsed: int(time.Since(startTime) / time.Millisecond), } b, _ := json.Marshal(entry) From 4c694d72d734dcc62b903d1c5a9a8a3dfb93f6ea Mon Sep 17 00:00:00 2001 From: man90 Date: Fri, 22 May 2026 10:55:26 +0200 Subject: [PATCH 5/5] Bump up version number --- handlers/getStatus.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers/getStatus.go b/handlers/getStatus.go index 4864da5..d2bcfc6 100644 --- a/handlers/getStatus.go +++ b/handlers/getStatus.go @@ -12,7 +12,7 @@ import ( ) var initTime = time.Now() -var version = "1.18.4" +var version = "1.19.0" func getStatus(w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(map[string]interface{}{