From 6ba59ff1b11c0bf7b102c706eb48508f85192f9b Mon Sep 17 00:00:00 2001 From: Tony Han Date: Mon, 13 May 2024 00:27:06 +0800 Subject: [PATCH 1/5] ListQueryObjectType should be filtered from the database, not from memory. --- .../OrchardCore.Lists/GraphQL/ListQueryObjectType.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs index 246cc35bdb6..f1c631e05ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs @@ -35,15 +35,14 @@ public ListQueryObjectType(IStringLocalizer S) var session = serviceProvider.GetService(); var accessor = serviceProvider.GetRequiredService(); - var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader("ContainedPublishedContentItems", x => LoadPublishedContentItemsForListAsync(x, session)); + var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader("ContainedPublishedContentItems", + x => LoadPublishedContentItemsForListAsync(x, session, g.GetArgument("skip"), g.GetArgument("first"))); - return ((await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync()) - .Skip(g.GetArgument("skip")) - .Take(g.GetArgument("first"))); + return await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync(); }); } - private static async Task> LoadPublishedContentItemsForListAsync(IEnumerable contentItemIds, ISession session) + private static async Task> LoadPublishedContentItemsForListAsync(IEnumerable contentItemIds, ISession session, int skip, int first) { if (contentItemIds is null || !contentItemIds.Any()) { @@ -54,6 +53,8 @@ private static async Task> LoadPublishedContentItem .With(ci => ci.Published) .With(cp => cp.ListContentItemId.IsIn(contentItemIds)) .OrderBy(o => o.Order) + .Skip(skip) + .Take(first) .ListAsync(); return query.ToLookup(k => k.As().ListContentItemId); From 6cb0584f70b862b58c4ce877b447cb28ce4c9bdf Mon Sep 17 00:00:00 2001 From: Tony Han Date: Mon, 13 May 2024 01:30:57 +0800 Subject: [PATCH 2/5] update code --- .../Queries/ContentItemsFieldType.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemsFieldType.cs b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemsFieldType.cs index 7a682b0268e..484494cf969 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemsFieldType.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.GraphQL/Queries/ContentItemsFieldType.cs @@ -56,7 +56,7 @@ public ContentItemsFieldType(string contentItemName, ISchema schema, IOptions { Name = "status", Description = "publication status of the content item", ResolvedType = new PublicationStatusGraphType(), DefaultValue = PublicationStatusEnum.Published } ); - Resolver = new LockedAsyncFieldResolver>(Resolve); + Resolver = new LockedAsyncFieldResolver>(ResolveAsync); schema.RegisterType(whereInput); schema.RegisterType(orderByInput); @@ -65,7 +65,7 @@ public ContentItemsFieldType(string contentItemName, ISchema schema, IOptions> Resolve(IResolveFieldContext context) + private async ValueTask> ResolveAsync(IResolveFieldContext context) { var versionOption = VersionOptions.Published; From 629594105b224a502301a6eeb865a139eb89ef60 Mon Sep 17 00:00:00 2001 From: Tony Han Date: Mon, 13 May 2024 01:33:17 +0800 Subject: [PATCH 3/5] Update src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Lists/GraphQL/ListQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs index f1c631e05ac..17fd3177a70 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs @@ -36,7 +36,7 @@ public ListQueryObjectType(IStringLocalizer S) var accessor = serviceProvider.GetRequiredService(); var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader("ContainedPublishedContentItems", - x => LoadPublishedContentItemsForListAsync(x, session, g.GetArgument("skip"), g.GetArgument("first"))); + x => LoadPublishedContentItemsForListAsync(x, session, g.GetArgument("skip"), g.GetArgument("first"))); return await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync(); }); From bf7aa5d9ead1e8f8bcf2e9bfcc5505ddcf172cce Mon Sep 17 00:00:00 2001 From: Tony Han Date: Mon, 13 May 2024 02:36:53 +0800 Subject: [PATCH 4/5] Update src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Lists/GraphQL/ListQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs index 17fd3177a70..0f389d95330 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs @@ -54,7 +54,7 @@ private static async Task> LoadPublishedContentItem .With(cp => cp.ListContentItemId.IsIn(contentItemIds)) .OrderBy(o => o.Order) .Skip(skip) - .Take(first) + .Take(count) .ListAsync(); return query.ToLookup(k => k.As().ListContentItemId); From a91e5d87dc00609eb285f6bb9f44f661cbcf6c7a Mon Sep 17 00:00:00 2001 From: Tony Han Date: Mon, 13 May 2024 02:37:11 +0800 Subject: [PATCH 5/5] Update src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Lists/GraphQL/ListQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs index 0f389d95330..0862a60aa53 100644 --- a/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Lists/GraphQL/ListQueryObjectType.cs @@ -42,7 +42,7 @@ public ListQueryObjectType(IStringLocalizer S) }); } - private static async Task> LoadPublishedContentItemsForListAsync(IEnumerable contentItemIds, ISession session, int skip, int first) + private static async Task> LoadPublishedContentItemsForListAsync(IEnumerable contentItemIds, ISession session, int skip, int count) { if (contentItemIds is null || !contentItemIds.Any()) {