From 193952e84d291ff35cc7c62a10b4f1bf78a50839 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sun, 15 Oct 2023 22:43:11 -0600 Subject: [PATCH] Fixed cache bug --- gql.go | 2 +- gql_node.go | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/gql.go b/gql.go index a952067..e26c05b 100644 --- a/gql.go +++ b/gql.go @@ -913,7 +913,7 @@ func (ctx *GQLExtContext) RegisterField(gql_type graphql.Type, gql_name string, val_ser, field_exists := ext[gv_tag] if field_exists == false { - return nil, fmt.Errorf("%s is not in the fields of %+v in the result", gv_tag, ext_type) + return nil, fmt.Errorf("%s is not in the fields of %+v in the result for %s - %+v", gv_tag, ext_type, gql_name, node) } if val_ser.TypeStack[0] == ErrorType { diff --git a/gql_node.go b/gql_node.go index c6cd017..bfd8c8c 100644 --- a/gql_node.go +++ b/gql_node.go @@ -57,7 +57,7 @@ func GetResolveFields(ctx *Context, p graphql.ResolveParams) []string { func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([]NodeResult, error) { fields := GetResolveFields(ctx.Context, p) - ctx.Context.Log.Logf("gql", "RESOLVE_NODES(%+v): %+v", ids, fields) + ctx.Context.Log.Logf("gql_resolve_node", "RESOLVE_NODES(%+v): %+v", ids, fields) resp_channels := map[uuid.UUID]chan Signal{} indices := map[uuid.UUID]int{} @@ -67,7 +67,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ if err != nil { return nil, err } - ctx.Context.Log.Logf("gql", "ACL Fields from request: %+v", ext_fields) + ctx.Context.Log.Logf("gql_resolve_node", "ACL Fields from request: %+v", ext_fields) responses := make([]NodeResult, len(ids)) @@ -100,14 +100,14 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ if resolve == true { read_signal = NewReadSignal(missing_exts) - ctx.Context.Log.Logf("gql_node", "sending read for %+v because of missing fields %+v", id, missing_exts) + ctx.Context.Log.Logf("gql_resolve_node", "sending read for %+v because of missing fields %+v", id, missing_exts) } else { - ctx.Context.Log.Logf("gql_node", "Using cached response for %+v(%d)", id, i) + ctx.Context.Log.Logf("gql_resolve_node", "Using cached response for %+v(%d)", id, i) responses[i] = node continue } } else { - ctx.Context.Log.Logf("gql_node", "sending read for %+v", id) + ctx.Context.Log.Logf("gql_resolve_node", "sending read for %+v", id) read_signal = NewReadSignal(ext_fields) } // Create a read signal, send it to the specified node, and add the wait to the response map if the send returns no error @@ -124,8 +124,6 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ ctx.Ext.FreeResponseChannel(read_signal.ID()) return nil, err } - - ctx.Context.Log.Logf("gql_node", "SENT_READ_SIGNAL to %+s", id) } errors := "" @@ -135,7 +133,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ if err != nil { return nil, err } - ctx.Context.Log.Logf("gql_node", "GQL node response: %+v", response) + ctx.Context.Log.Logf("gql_resolve_node", "GQL node response: %+v", response) error_signal, is_error := response.(*ErrorSignal) if is_error { @@ -158,6 +156,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ cache, exists := ctx.NodeCache[read_response.NodeID] if exists == true { + ctx.Context.Log.Logf("gql_resolve_node", "Merging new response with cached: %s, %+v - %+v", read_response.NodeID, cache, read_response.Extensions) for ext_type, fields := range(read_response.Extensions) { cached_fields, exists := cache.Data[ext_type] if exists == true { @@ -166,15 +165,18 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([ } } } + // TODO: put the cached results back into results to resolve + responses[idx] = cache } else { + ctx.Context.Log.Logf("gql_resolve_node", "Adding new response to node cache: %s, %+v", read_response.NodeID, read_response.Extensions) ctx.NodeCache[read_response.NodeID] = responses[idx] } - } - ctx.Context.Log.Logf("gql_node", "RESOLVED_NODES %+v - %+v", ids, responses) if errors != "" { return nil, fmt.Errorf(errors) } + + ctx.Context.Log.Logf("gql_resolve_node", "RESOLVED_NODES %+v - %+v", ids, responses) return responses, nil }