perf(graph): cache merged SDL and SchemaUpdate per ref (#841)
Release / release (push) Failing after 54s
schemas / vulnerabilities (push) Successful in 2m11s
schemas / check (push) Successful in 2m36s
schemas / check-release (push) Successful in 2m54s
pre-commit / pre-commit (push) Successful in 8m10s
schemas / build (push) Successful in 5m43s
schemas / deploy-prod (push) Successful in 1m9s
Release / release (push) Failing after 54s
schemas / vulnerabilities (push) Successful in 2m11s
schemas / check (push) Successful in 2m36s
schemas / check-release (push) Successful in 2m54s
pre-commit / pre-commit (push) Successful in 8m10s
schemas / build (push) Successful in 5m43s
schemas / deploy-prod (push) Successful in 1m9s
This commit was merged in pull request #841.
This commit is contained in:
@@ -210,6 +210,7 @@ func (r *mutationResolver) UpdateSubGraph(ctx context.Context, input model.Input
|
||||
SubGraphs: subGraphs,
|
||||
CosmoRouterConfig: &cosmoConfig,
|
||||
}
|
||||
r.Cache.SetSchemaUpdate(orgId, input.Ref, update)
|
||||
|
||||
r.Logger.Info(
|
||||
"Publishing schema update to subscribers",
|
||||
@@ -280,13 +281,25 @@ func (r *queryResolver) Supergraph(ctx context.Context, ref string, isAfter *str
|
||||
if isAfter != nil {
|
||||
after = *isAfter
|
||||
}
|
||||
services, lastUpdate := r.Cache.Services(orgId, ref, after)
|
||||
_, lastUpdate := r.Cache.Services(orgId, ref, after)
|
||||
if after == lastUpdate {
|
||||
return &model.Unchanged{
|
||||
ID: lastUpdate,
|
||||
MinDelaySeconds: 10,
|
||||
}, nil
|
||||
}
|
||||
|
||||
if cached := r.Cache.GetMergedSDL(orgId, ref); cached != nil {
|
||||
id, sdl, subGraphs := cached.Unpack()
|
||||
return &model.SubGraphs{
|
||||
ID: id,
|
||||
SubGraphs: subGraphs,
|
||||
Sdl: sdl,
|
||||
MinDelaySeconds: 10,
|
||||
}, nil
|
||||
}
|
||||
|
||||
services, _ := r.Cache.Services(orgId, ref, "")
|
||||
subGraphs := make([]*model.SubGraph, len(services))
|
||||
serviceSDLs := make([]string, len(services))
|
||||
for i, id := range services {
|
||||
@@ -302,6 +315,7 @@ func (r *queryResolver) Supergraph(ctx context.Context, ref string, isAfter *str
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
r.Cache.SetMergedSDL(orgId, ref, lastUpdate, sdl, subGraphs)
|
||||
return &model.SubGraphs{
|
||||
ID: lastUpdate,
|
||||
SubGraphs: subGraphs,
|
||||
@@ -344,6 +358,16 @@ func (r *queryResolver) LatestSchema(ctx context.Context, ref string) (*model.Sc
|
||||
return nil, fmt.Errorf("no authentication provided")
|
||||
}
|
||||
|
||||
if cached := r.Cache.GetSchemaUpdate(orgId, ref); cached != nil {
|
||||
r.Logger.Info(
|
||||
"Latest schema served from cache",
|
||||
"ref", ref,
|
||||
"orgId", orgId,
|
||||
"id", cached.ID,
|
||||
)
|
||||
return cached, nil
|
||||
}
|
||||
|
||||
// Get current services and schema
|
||||
services, lastUpdate := r.Cache.Services(orgId, ref, "")
|
||||
r.Logger.Info(
|
||||
@@ -385,6 +409,7 @@ func (r *queryResolver) LatestSchema(ctx context.Context, ref string) (*model.Sc
|
||||
SubGraphs: subGraphs,
|
||||
CosmoRouterConfig: &cosmoConfig,
|
||||
}
|
||||
r.Cache.SetSchemaUpdate(orgId, ref, update)
|
||||
|
||||
r.Logger.Info(
|
||||
"Latest schema fetched",
|
||||
|
||||
Reference in New Issue
Block a user