💄 Optimize timeline cursor picking

This commit is contained in:
2026-01-07 19:44:53 +08:00
parent 4ebbda1b14
commit d2806fdc3a

View File

@@ -58,17 +58,17 @@ class ActivityListNotifier
// Find the latest createdAt timestamp from all items for cursor-based pagination // Find the latest createdAt timestamp from all items for cursor-based pagination
// This ensures we get items created before this timestamp, regardless of sort order // This ensures we get items created before this timestamp, regardless of sort order
if (items.isNotEmpty) { if (items.isNotEmpty) {
final latestCreatedAt = items final newestCreatedAt = items
.where((e) => e.type.startsWith('posts.')) .where((e) => e.type.startsWith('posts.'))
.map((e) => e.createdAt) .map((e) => e.createdAt)
.reduce((a, b) => a.isBefore(b) ? a : b); .reduce((a, b) => a.isBefore(b) ? a : b);
if (cursor != null) { if (cursor != null) {
final prevCursor = DateTime.tryParse(cursor!); final prevCursor = DateTime.tryParse(cursor!);
if (prevCursor != null && prevCursor.isAfter(latestCreatedAt)) { if (prevCursor != null && prevCursor.isAfter(newestCreatedAt)) {
cursor = latestCreatedAt.toUtc().toIso8601String(); cursor = newestCreatedAt.toUtc().toIso8601String();
} }
} else { } else {
cursor = latestCreatedAt.toUtc().toIso8601String(); cursor = newestCreatedAt.toUtc().toIso8601String();
} }
} }