From 4cf043b916f5576ee8bcb07c022fa607c960fe6a Mon Sep 17 00:00:00 2001 From: Lalit Deore Date: Tue, 7 Apr 2026 18:58:43 +0530 Subject: [PATCH] fix - datastore suborg distribution issue due to cache --- db-connector.go | 30 +++++++++++++++--------------- shared.go | 8 ++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/db-connector.go b/db-connector.go index b2dbb22f..6ad0e882 100755 --- a/db-connector.go +++ b/db-connector.go @@ -16467,21 +16467,6 @@ func GetAllCacheKeys(ctx context.Context, orgId string, category string, max int } - // Only cache if NO cursor at all. - // Otherwise we need to track and clean up all cursors(?) - if project.CacheDb { - newcache, err := json.Marshal(cacheKeys) - if err != nil { - log.Printf("[WARNING] Failed marshalling cacheKeys: %s", err) - return cacheKeys, cursor, nil - } - - err = SetCache(ctx, cacheKey, newcache, 5) - if err != nil { - log.Printf("[WARNING] Failed updating cache keys cache: %s", err) - } - } - foundOrg, err := GetOrg(ctx, orgId) if err == nil && len(foundOrg.CreatorOrg) > 0 && foundOrg.CreatorOrg != orgId { parentOrg, err := GetOrg(ctx, foundOrg.CreatorOrg) @@ -16516,6 +16501,21 @@ func GetAllCacheKeys(ctx context.Context, orgId string, category string, max int } } + // Only cache if NO cursor at all. + // Otherwise we need to track and clean up all cursors(?) + if project.CacheDb { + newcache, err := json.Marshal(cacheKeys) + if err != nil { + log.Printf("[WARNING] Failed marshalling cacheKeys: %s", err) + return cacheKeys, cursor, nil + } + + err = SetCache(ctx, cacheKey, newcache, 5) + if err != nil { + log.Printf("[WARNING] Failed updating cache keys cache: %s", err) + } + } + return cacheKeys, cursor, nil } diff --git a/shared.go b/shared.go index 99753710..e561b725 100644 --- a/shared.go +++ b/shared.go @@ -20896,6 +20896,14 @@ func HandleDeleteCacheKeyPost(resp http.ResponseWriter, request *http.Request) { DeleteCache(ctx, fmt.Sprintf("%s_%s", entity, cacheId)) DeleteCache(ctx, fmt.Sprintf("%s_%s", entity, url.QueryEscape(cacheId))) + normalizedCategory := strings.ReplaceAll(strings.ToLower(tmpData.Category), " ", "_") + if normalizedCategory == "default" { + normalizedCategory = "" + } + DeleteCache(ctx, fmt.Sprintf("%s__%s_%s", entity, org.Id, normalizedCategory)) + DeleteCache(ctx, fmt.Sprintf("%s__%s_", entity, org.Id)) + DeleteCache(ctx, fmt.Sprintf("%s__%s", entity, org.Id)) + result := ResultChecker{ Success: true, Reason: fmt.Sprintf("Key '%s' deleted", tmpData.Key),