From 39b43095de3e87101eae19597e2cf6c990d10465 Mon Sep 17 00:00:00 2001 From: Max Blazejewski Date: Tue, 18 Jun 2024 12:13:55 +0200 Subject: [PATCH] Make cache non-case-sensitive (#19) --- handlers/GetAdventurerSearch.go | 4 ++++ handlers/GetGuild.go | 4 ++++ handlers/GetGuildSearch.go | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/handlers/GetAdventurerSearch.go b/handlers/GetAdventurerSearch.go index fbb3863..ad5a540 100644 --- a/handlers/GetAdventurerSearch.go +++ b/handlers/GetAdventurerSearch.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "bdo-rest-api/cache" "bdo-rest-api/models" @@ -28,6 +29,9 @@ func GetAdventurerSearch(w http.ResponseWriter, r *http.Request) { return } + // All names are non-case-sensitive, so this will allow to utilise cache better + query = strings.ToLower(query) + // Look for cached data, then run the scraper if needed data, status, date, expires, found := profileSearchCache.GetRecord([]string{region, query, fmt.Sprint(searchType), fmt.Sprint(page)}) if !found { diff --git a/handlers/GetGuild.go b/handlers/GetGuild.go index 5a45e0a..24da5ff 100644 --- a/handlers/GetGuild.go +++ b/handlers/GetGuild.go @@ -3,6 +3,7 @@ package handlers import ( "encoding/json" "net/http" + "strings" "bdo-rest-api/cache" "bdo-rest-api/models" @@ -25,6 +26,9 @@ func GetGuild(w http.ResponseWriter, r *http.Request) { return } + // All names are non-case-sensitive, so this will allow to utilise cache better + name = strings.ToLower(name) + // Look for cached data, then run the scraper if needed data, status, date, expires, found := guildProfilesCache.GetRecord([]string{region, name}) if !found { diff --git a/handlers/GetGuildSearch.go b/handlers/GetGuildSearch.go index 86d7b73..03378bf 100644 --- a/handlers/GetGuildSearch.go +++ b/handlers/GetGuildSearch.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "net/http" + "strings" "bdo-rest-api/cache" "bdo-rest-api/models" @@ -27,6 +28,9 @@ func GetGuildSearch(w http.ResponseWriter, r *http.Request) { return } + // All names are non-case-sensitive, so this will allow to utilise cache better + name = strings.ToLower(name) + // Look for cached data, then run the scraper if needed data, status, date, expires, found := guildSearchCache.GetRecord([]string{region, name, fmt.Sprint(page)}) if !found {