Skip to content

Add pagination to openings, pages, events#185

Open
TGyAkos wants to merge 9 commits intomainfrom
feature/pagination
Open

Add pagination to openings, pages, events#185
TGyAkos wants to merge 9 commits intomainfrom
feature/pagination

Conversation

@TGyAkos
Copy link
Copy Markdown

@TGyAkos TGyAkos commented Mar 5, 2026

No description provided.

@TGyAkos TGyAkos self-assigned this Mar 5, 2026
@TGyAkos TGyAkos added this to StartSCH Mar 5, 2026
@TGyAkos TGyAkos linked an issue Mar 5, 2026 that may be closed by this pull request
3 tasks
Comment on lines +118 to +138
private Task<List<object>> FetchPage(string? after)
{
IEnumerable<object> items = _event!.Children
.Concat<object>(_event.Posts)
.OrderByDescending(o => o switch
{
Event e => e.Start,
Post p => p.Created,
_ => throw new InvalidOperationException()
});

if (after != null)
{
int comma = after.IndexOf(',');
Instant afterInstant = InstantPattern.ExtendedIso.Parse(after[..comma]).GetValueOrThrow();
int afterId = int.Parse(after.AsSpan(comma + 1));
items = items.Where(o => IsAfterCursor(o, afterInstant, afterId));
}

return Task.FromResult(items.Take(30).ToList());
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the issue here is that Entity Framework can't translate IsAfterCursor to SQL, that's why you had to use .ToList() instead of .ToListAsync(). unfortunately when this happens, EF just loads the whole table from the DB and runs the query client-side, which is very bad for performance.

you could either use a custom SQL UNION query with a custom result type (https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/whatsnew#raw-sql-queries-for-unmapped-types) or just do 2 queries, both with a 30 limit

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrote the function, so it makes 2 queries instead

if it functions correclty, please resolve this conversation

@TGyAkos TGyAkos requested a review from albi005 March 19, 2026 17:26
int comma = after.IndexOf(',');
Instant afterInstant = InstantPattern.ExtendedIso.Parse(after[..comma]).GetValueOrThrow();
int afterId = int.Parse(after.AsSpan(comma + 1));
query = query.Where(o => IsAfterCursor(o, afterInstant, afterId));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here

<ResourceUnavailable Status="@status"/>
@if (_event != null)
{
<InfiniteList TItem="object"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the .razor parser seems to work better when all C# code is prefixed with @. please use it everywhere. for example:

TItem="object" -> TItem="@object"

@albi005
Copy link
Copy Markdown
Member

albi005 commented Mar 19, 2026

EventPage and PagePage both need to load trees. currently this is done using the methods in SqlQueries, but those don't support pagination. for now perhaps we could query the next 30 top-level entities, then load the descendants in a separate query?

@albi005 albi005 removed this from StartSCH Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use pagination on more pages

2 participants