Micro fixes.

This commit is contained in:
2024-02-15 10:21:51 +00:00
parent 0bdea741bf
commit ebbb1c53f5
4 changed files with 26 additions and 1 deletions
+4
View File
@@ -23,3 +23,7 @@ func cacheLookup(hash string) []byte {
} }
return nil return nil
} }
func cacheDelete(hash string) {
cfg.Cache.CacheClient.Delete(hash)
}
+2 -1
View File
@@ -75,6 +75,7 @@ type parseGraphQLQueryResult struct {
operationName string operationName string
cacheRequest bool cacheRequest bool
cacheTime int cacheTime int
cacheRefresh bool
shouldBlock bool shouldBlock bool
shouldIgnore bool shouldIgnore bool
} }
@@ -144,7 +145,7 @@ func parseGraphQLQuery(c *fiber.Ctx) (res *parseGraphQLQueryResult) {
} }
} }
if arg.Name.Value == "refresh" { if arg.Name.Value == "refresh" {
res.cacheRequest = arg.Value.GetValue().(bool) res.cacheRefresh = arg.Value.GetValue().(bool)
} }
} }
} }
+15
View File
@@ -119,6 +119,21 @@ func (suite *Tests) Test_parseGraphQLQuery() {
}, },
}, },
{
name: "test valid query with op name, force refreshed cache",
suppliedQuery: queries{
body: "{\"query\":\"query MyQuery @cached(refresh: true) { tg_users(where: {handle: {_eq: \\\"tozuo\\\"}}) { id __typename } }\", \"variables\": {\"id\": \"1\"}}",
},
wantResults: results{
is_cached: true,
cached_ttl: 0,
shouldBlock: false,
shouldIgnore: false,
op_name: "MyQuery",
op_type: "query",
},
},
{ {
name: "test valid query with op name, cache and INVALID ttl", name: "test valid query with op name, cache and INVALID ttl",
suppliedQuery: queries{ suppliedQuery: queries{
+5
View File
@@ -136,6 +136,11 @@ func processGraphQLRequest(c *fiber.Ctx) error {
wasCached := false wasCached := false
if parsedResult.cacheRefresh {
cfg.Logger.Debug("Cache refresh requested via query", map[string]interface{}{"user_id": extractedUserID, "request_uuid": c.Locals("request_uuid")})
cacheDelete(calculateHash(c))
}
// Handling Cache Logic // Handling Cache Logic
if parsedResult.cacheRequest || cfg.Cache.CacheEnable { if parsedResult.cacheRequest || cfg.Cache.CacheEnable {
cfg.Logger.Debug("Cache enabled", map[string]interface{}{"via_query": parsedResult.cacheRequest, "via_env": cfg.Cache.CacheEnable}) cfg.Logger.Debug("Cache enabled", map[string]interface{}{"via_query": parsedResult.cacheRequest, "via_env": cfg.Cache.CacheEnable})