Conversation
| 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()); | ||
| } |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
rewrote the function, so it makes 2 queries instead
if it functions correclty, please resolve this conversation
| 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)); |
| <ResourceUnavailable Status="@status"/> | ||
| @if (_event != null) | ||
| { | ||
| <InfiniteList TItem="object" |
There was a problem hiding this comment.
the .razor parser seems to work better when all C# code is prefixed with @. please use it everywhere. for example:
TItem="object" -> TItem="@object"
|
|
No description provided.