Fixed cache bug

gql_cataclysm
noah metz 2023-10-15 22:43:11 -06:00
parent d930d78351
commit 193952e84d
2 changed files with 13 additions and 11 deletions

@ -913,7 +913,7 @@ func (ctx *GQLExtContext) RegisterField(gql_type graphql.Type, gql_name string,
val_ser, field_exists := ext[gv_tag] val_ser, field_exists := ext[gv_tag]
if field_exists == false { 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 { if val_ser.TypeStack[0] == ErrorType {

@ -57,7 +57,7 @@ func GetResolveFields(ctx *Context, p graphql.ResolveParams) []string {
func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([]NodeResult, error) { func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([]NodeResult, error) {
fields := GetResolveFields(ctx.Context, p) 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{} resp_channels := map[uuid.UUID]chan Signal{}
indices := map[uuid.UUID]int{} indices := map[uuid.UUID]int{}
@ -67,7 +67,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
if err != nil { if err != nil {
return nil, err 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)) responses := make([]NodeResult, len(ids))
@ -100,14 +100,14 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
if resolve == true { if resolve == true {
read_signal = NewReadSignal(missing_exts) 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 { } 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 responses[i] = node
continue continue
} }
} else { } 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) 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 // 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()) ctx.Ext.FreeResponseChannel(read_signal.ID())
return nil, err return nil, err
} }
ctx.Context.Log.Logf("gql_node", "SENT_READ_SIGNAL to %+s", id)
} }
errors := "" errors := ""
@ -135,7 +133,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
if err != nil { if err != nil {
return nil, err 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) error_signal, is_error := response.(*ErrorSignal)
if is_error { if is_error {
@ -158,6 +156,7 @@ func ResolveNodes(ctx *ResolveContext, p graphql.ResolveParams, ids []NodeID) ([
cache, exists := ctx.NodeCache[read_response.NodeID] cache, exists := ctx.NodeCache[read_response.NodeID]
if exists == true { 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) { for ext_type, fields := range(read_response.Extensions) {
cached_fields, exists := cache.Data[ext_type] cached_fields, exists := cache.Data[ext_type]
if exists == true { 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 { } 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.NodeCache[read_response.NodeID] = responses[idx]
} }
} }
ctx.Context.Log.Logf("gql_node", "RESOLVED_NODES %+v - %+v", ids, responses)
if errors != "" { if errors != "" {
return nil, fmt.Errorf(errors) return nil, fmt.Errorf(errors)
} }
ctx.Context.Log.Logf("gql_resolve_node", "RESOLVED_NODES %+v - %+v", ids, responses)
return responses, nil return responses, nil
} }