Skip to content

Commit

Permalink
Allocation improvements. (#1009)
Browse files Browse the repository at this point in the history
* Allocation improvements.

* Fix usings.
  • Loading branch information
SebastianStehle authored Jul 26, 2023
1 parent 8a685d5 commit bc97133
Show file tree
Hide file tree
Showing 13 changed files with 175 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using GraphQL.Types;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Contents;
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types.Primitives;
using Squidex.Domain.Apps.Entities.Schemas;

namespace Squidex.Domain.Apps.Entities.Contents.GraphQL.Types;

Expand All @@ -34,69 +35,79 @@ public ApplicationMutations(Builder builder, IEnumerable<SchemaInfo> schemas)

var nonNullContentType = new NonNullGraphType(contentType);

AddField(new FieldType
// Calculate the named if once to avoid allocations.
var schemaid = schemaInfo.Schema.NamedId();

AddField(new FieldTypeWithSchemaNamedId
{
Name = $"create{schemaInfo.TypeName}Content",
Arguments = ContentActions.Create.Arguments(inputType),
ResolvedType = contentType,
Resolver = ContentActions.Create.Resolver,
Description = $"Creates an {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo);
Description = $"Creates an {schemaInfo.DisplayName} content.",
SchemaId = schemaInfo.Schema.NamedId()
});

AddField(new FieldType
AddField(new FieldTypeWithSchemaNamedId
{
Name = $"update{schemaInfo.TypeName}Content",
Arguments = ContentActions.Update.Arguments(inputType),
ResolvedType = contentType,
Resolver = ContentActions.Update.Resolver,
Description = $"Update an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo);
Description = $"Update an {schemaInfo.DisplayName} content by id.",
SchemaId = schemaInfo.Schema.NamedId()
});

AddField(new FieldType
AddField(new FieldTypeWithSchemaNamedId
{
Name = $"upsert{schemaInfo.TypeName}Content",
Arguments = ContentActions.Upsert.Arguments(inputType),
ResolvedType = contentType,
Resolver = ContentActions.Upsert.Resolver,
Description = $"Upsert an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo);
Description = $"Upsert an {schemaInfo.DisplayName} content by id.",
SchemaId = schemaInfo.Schema.NamedId()
});

AddField(new FieldType
AddField(new FieldTypeWithSchemaNamedId
{
Name = $"patch{schemaInfo.TypeName}Content",
Arguments = ContentActions.Patch.Arguments(inputType),
ResolvedType = contentType,
Resolver = ContentActions.Patch.Resolver,
Description = $"Patch an {schemaInfo.DisplayName} content by id."
}).WithSchemaNamedId(schemaInfo);
Description = $"Patch an {schemaInfo.DisplayName} content by id.",
SchemaId = schemaInfo.Schema.NamedId()
});

AddField(new FieldType
AddField(new FieldTypeWithSchemaNamedId
{
Name = $"change{schemaInfo.TypeName}Content",
Arguments = ContentActions.ChangeStatus.Arguments,
ResolvedType = contentType,
Resolver = ContentActions.ChangeStatus.Resolver,
Description = $"Change a {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo);
Description = $"Change a {schemaInfo.DisplayName} content.",
SchemaId = schemaInfo.Schema.NamedId()
});

AddField(new FieldType
AddField(new FieldTypeWithSchemaNamedId
{
Name = $"delete{schemaInfo.TypeName}Content",
Arguments = ContentActions.Delete.Arguments,
ResolvedType = EntitySavedGraphType.NonNull,
Resolver = ContentActions.Delete.Resolver,
Description = $"Delete an {schemaInfo.DisplayName} content."
}).WithSchemaNamedId(schemaInfo);
Description = $"Delete an {schemaInfo.DisplayName} content.",
SchemaId = schemaInfo.Schema.NamedId()
});

AddField(new FieldType
AddField(new FieldTypeWithSchemaNamedId
{
Name = $"publish{schemaInfo.TypeName}Content",
Arguments = ContentActions.ChangeStatus.Arguments,
ResolvedType = contentType,
Resolver = ContentActions.ChangeStatus.Resolver,
Description = $"Publish a {schemaInfo.DisplayName} content.",
DeprecationReason = $"Use 'change{schemaInfo.TypeName}Content' instead"
}).WithSchemaNamedId(schemaInfo);
DeprecationReason = $"Use 'change{schemaInfo.TypeName}Content' instead",
SchemaId = schemaInfo.Schema.NamedId()
});
}

Description = "The app mutations.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@ public ApplicationQueries(Builder builder, IEnumerable<SchemaInfo> schemaInfos)

private void AddContentFind(SchemaInfo schemaInfo, IGraphType contentType)
{
AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"find{schemaInfo.TypeName}Content",
Arguments = ContentActions.Find.Arguments,
ResolvedType = contentType,
Resolver = ContentActions.Find.Resolver,
Description = $"Find an {schemaInfo.DisplayName} content by id."
}).WithSchemaId(schemaInfo);
Description = $"Find an {schemaInfo.DisplayName} content by id.",
SchemaId = schemaInfo.Schema.Id
});
}

private void AddContentQueries(Builder builder, SchemaInfo schemaInfo, IGraphType contentType)
{
AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"query{schemaInfo.TypeName}Contents",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = new ListGraphType(new NonNullGraphType(contentType)),
Resolver = ContentActions.QueryOrReferencing.Query,
Description = $"Query {schemaInfo.DisplayName} content items."
}).WithSchemaId(schemaInfo);
Description = $"Query {schemaInfo.DisplayName} content items.",
SchemaId = schemaInfo.Schema.Id
});

var contentResultTyp = builder.GetContentResultType(schemaInfo);

Expand All @@ -65,14 +67,15 @@ private void AddContentQueries(Builder builder, SchemaInfo schemaInfo, IGraphTyp
return;
}

AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"query{schemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.QueryWithTotal,
Description = $"Query {schemaInfo.DisplayName} content items with total count."
}).WithSchemaId(schemaInfo);
Description = $"Query {schemaInfo.DisplayName} content items with total count.",
SchemaId = schemaInfo.Schema.Id
});
}

private void AddContentQuery(Builder builder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,30 @@ public void Initialize(Builder builder, SchemaInfo schemaInfo)
{
if (fieldInfo.Field.IsComponentLike())
{
AddField(new FieldType
AddField(new FieldTypeWithSourceName
{
Name = fieldInfo.FieldNameDynamic,
Arguments = ContentActions.Json.Arguments,
ResolvedType = Scalars.Json,
Resolver = FieldVisitor.JsonPath,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(fieldInfo);
Description = fieldInfo.Field.RawProperties.Hints,
SourceName = fieldInfo.Field.Name
});
}

var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo);

if (resolvedType != null && resolver != null)
{
AddField(new FieldType
AddField(new FieldTypeWithSourceName
{
Name = fieldInfo.FieldName,
Arguments = args,
ResolvedType = resolvedType,
Resolver = resolver,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(fieldInfo);
Description = fieldInfo.Field.RawProperties.Hints,
SourceName = fieldInfo.Field.Name
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,15 @@ private void AddReferencingQueries(Builder builder, SchemaInfo referencingSchema
{
var contentType = builder.GetContentType(referencingSchemaInfo);

AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"referencing{referencingSchemaInfo.TypeName}Contents",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = new ListGraphType(new NonNullGraphType(contentType)),
Resolver = ContentActions.QueryOrReferencing.Referencing,
Description = $"Query {referencingSchemaInfo.DisplayName} content items."
}).WithSchemaId(referencingSchemaInfo);
Description = $"Query {referencingSchemaInfo.DisplayName} content items.",
SchemaId = referencingSchemaInfo.Schema.Id
});

var contentResultTyp = builder.GetContentResultType(referencingSchemaInfo);

Expand All @@ -111,28 +112,30 @@ private void AddReferencingQueries(Builder builder, SchemaInfo referencingSchema
return;
}

AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"referencing{referencingSchemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.ReferencingWithTotal,
Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count."
}).WithSchemaId(referencingSchemaInfo);
Description = $"Query {referencingSchemaInfo.DisplayName} content items with total count.",
SchemaId = referencingSchemaInfo.Schema.Id
});
}

private void AddReferencesQueries(Builder builder, SchemaInfo referencesSchemaInfo)
{
var contentType = builder.GetContentType(referencesSchemaInfo);

AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"references{referencesSchemaInfo.TypeName}Contents",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = new ListGraphType(new NonNullGraphType(contentType)),
Resolver = ContentActions.QueryOrReferencing.References,
Description = $"Query {referencesSchemaInfo.DisplayName} content items."
}).WithSchemaId(referencesSchemaInfo);
Description = $"Query {referencesSchemaInfo.DisplayName} content items.",
SchemaId = referencesSchemaInfo.Schema.Id
});

var contentResultTyp = builder.GetContentResultType(referencesSchemaInfo);

Expand All @@ -141,14 +144,15 @@ private void AddReferencesQueries(Builder builder, SchemaInfo referencesSchemaIn
return;
}

AddField(new FieldType
AddField(new FieldTypeWithSchemaId
{
Name = $"references{referencesSchemaInfo.TypeName}ContentsWithTotal",
Arguments = ContentActions.QueryOrReferencing.Arguments,
ResolvedType = contentResultTyp,
Resolver = ContentActions.QueryOrReferencing.ReferencesWithTotal,
Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count."
}).WithSchemaId(referencesSchemaInfo);
Description = $"Query {referencesSchemaInfo.DisplayName} content items with total count.",
SchemaId = referencesSchemaInfo.Schema.Id
});
}

private static bool IsReference(SchemaInfo from, SchemaInfo to)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@ public DataFlatGraphType(Builder builder, SchemaInfo schemaInfo)
{
if (fieldInfo.Field.IsComponentLike())
{
AddField(new FieldType
AddField(new FieldTypeWithSourceName
{
Name = fieldInfo.FieldNameDynamic,
Arguments = ContentActions.Json.Arguments,
ResolvedType = Scalars.Json,
Resolver = FieldVisitor.JsonPath,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(fieldInfo);
Description = fieldInfo.Field.RawProperties.Hints,
SourceName = fieldInfo.Field.Name
});
}

var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo);

if (resolver != null)
{
AddField(new FieldType
AddField(new FieldTypeWithSourceName
{
Name = fieldInfo.FieldName,
Arguments = args,
ResolvedType = resolvedType,
Resolver = resolver,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(fieldInfo);
Description = fieldInfo.Field.RawProperties.Hints,
SourceName = fieldInfo.Field.Name
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,26 @@ public DataGraphType(Builder builder, SchemaInfo schemaInfo)

foreach (var partitionKey in partitioning.AllKeys)
{
fieldGraphType.AddField(new FieldType
fieldGraphType.AddField(new FieldTypeWithSourceName
{
Name = partitionKey.EscapePartition(),
Arguments = ContentActions.Json.Arguments,
ResolvedType = Scalars.Json,
Resolver = FieldVisitor.JsonPath,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(partitionKey);
Description = fieldInfo.Field.RawProperties.Hints,
SourceName = partitionKey
});
}

fieldGraphType.Description = $"The dynamic structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content type.";

AddField(new FieldType
AddField(new FieldTypeWithSourceName
{
Name = fieldInfo.FieldNameDynamic,
ResolvedType = fieldGraphType,
Resolver = ContentResolvers.Field
}).WithSourceName(fieldInfo);
Resolver = ContentResolvers.Field,
SourceName = fieldInfo.Field.Name
});
}

var (resolvedType, resolver, args) = builder.GetGraphType(fieldInfo);
Expand All @@ -65,24 +67,26 @@ public DataGraphType(Builder builder, SchemaInfo schemaInfo)

foreach (var partitionKey in partitioning.AllKeys)
{
fieldGraphType.AddField(new FieldType
fieldGraphType.AddField(new FieldTypeWithSourceName
{
Name = partitionKey.EscapePartition(),
Arguments = args,
ResolvedType = resolvedType,
Resolver = resolver,
Description = fieldInfo.Field.RawProperties.Hints
}).WithSourceName(partitionKey);
Description = fieldInfo.Field.RawProperties.Hints,
SourceName = partitionKey
});
}

fieldGraphType.Description = $"The structure of the {fieldInfo.DisplayName} field of the {schemaInfo.DisplayName} content type.";

AddField(new FieldType
AddField(new FieldTypeWithSourceName
{
Name = fieldInfo.FieldName,
ResolvedType = fieldGraphType,
Resolver = ContentResolvers.Field
}).WithSourceName(fieldInfo);
Resolver = ContentResolvers.Field,
SourceName = fieldInfo.Field.Name,
});
}
}

Expand Down
Loading

0 comments on commit bc97133

Please sign in to comment.