Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ListQueryObjectType should be filtered from the database #16037

Merged
merged 8 commits into from
May 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,14 @@ public ListQueryObjectType(IStringLocalizer<ListQueryObjectType> S)
var session = serviceProvider.GetService<ISession>();
var accessor = serviceProvider.GetRequiredService<IDataLoaderContextAccessor>();

var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader<string, ContentItem>("ContainedPublishedContentItems", x => LoadPublishedContentItemsForListAsync(x, session));
var dataLoader = accessor.Context.GetOrAddCollectionBatchLoader<string, ContentItem>("ContainedPublishedContentItems",
x => LoadPublishedContentItemsForListAsync(x, session, g.GetArgument<int>("skip"), g.GetArgument<int>("first")));
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved

return ((await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync())
.Skip(g.GetArgument<int>("skip"))
.Take(g.GetArgument<int>("first")));
return await dataLoader.LoadAsync(g.Source.ContentItem.ContentItemId).GetResultAsync();
});
}

private static async Task<ILookup<string, ContentItem>> LoadPublishedContentItemsForListAsync(IEnumerable<string> contentItemIds, ISession session)
private static async Task<ILookup<string, ContentItem>> LoadPublishedContentItemsForListAsync(IEnumerable<string> contentItemIds, ISession session, int skip, int first)
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved
{
if (contentItemIds is null || !contentItemIds.Any())
{
Expand All @@ -54,6 +53,8 @@ private static async Task<ILookup<string, ContentItem>> LoadPublishedContentItem
.With<ContentItemIndex>(ci => ci.Published)
.With<ContainedPartIndex>(cp => cp.ListContentItemId.IsIn(contentItemIds))
.OrderBy(o => o.Order)
.Skip(skip)
.Take(first)
hyzx86 marked this conversation as resolved.
Show resolved Hide resolved
.ListAsync();

return query.ToLookup(k => k.As<ContainedPart>().ListContentItemId);
Expand Down