loading gradually player sessions instead all at once
This commit is contained in:
@@ -62,11 +62,18 @@ export async function getNameHistory(steamid: string): Promise<NameHistoryEntry[
|
||||
);
|
||||
}
|
||||
|
||||
export async function getSessions(steamid: string, limit = 100): Promise<SessionEntry[]> {
|
||||
export async function getSessions(steamid: string, limit = 10, offset = 0): Promise<SessionEntry[]> {
|
||||
// The maps_played subquery finds every map_history period that overlaps
|
||||
// this session's [start, end] window (same overlap logic used elsewhere
|
||||
// in the app), and concatenates the names. A session can span more than
|
||||
// one map if the player stayed connected through a map change.
|
||||
//
|
||||
// This subquery runs once per returned row, and gets slower as
|
||||
// map_history grows — which is exactly why this is paginated at a small
|
||||
// page size (10) rather than fetching a large batch at once. A profile
|
||||
// with thousands of historical sessions was taking 20-30+ seconds to
|
||||
// load because this ran against a much larger LIMIT on every visit,
|
||||
// regardless of whether anyone ever scrolled down to see older sessions.
|
||||
return query<SessionEntry>(
|
||||
`SELECT
|
||||
s.session_id,
|
||||
@@ -83,8 +90,8 @@ export async function getSessions(steamid: string, limit = 100): Promise<Session
|
||||
FROM playtime_display_sessions s
|
||||
WHERE s.steamid = ?
|
||||
ORDER BY s.session_start_dt DESC
|
||||
LIMIT ?`,
|
||||
[steamid, limit],
|
||||
LIMIT ? OFFSET ?`,
|
||||
[steamid, limit, offset],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user