File size: 1,027 Bytes
645efc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/**

 * Decide whether the paginated sessions list should be silently

 * re-fetched after an overview poll.

 *

 * The dashboard's FastAPI server and a terminal CLI are separate

 * processes that share the same SQLite session DB. There is no

 * inter-process push channel, so the Sessions page polls the 50 newest

 * sessions every few seconds (the "overview" poll). When that poll

 * surfaces a session id at the head of the list that we have not seen

 * before, a new session was created in another process and the

 * paginated list is stale — refresh it.

 *

 * Returns false on the very first poll (no baseline yet) and when

 * either id is null (empty DB / transient empty response), so we never

 * trigger a spurious reload on mount or while the DB is empty.

 */
export function shouldRefreshSessions(

  prevNewestId: string | null,

  currentNewestId: string | null,

): boolean {
  return (
    prevNewestId !== null &&
    currentNewestId !== null &&
    prevNewestId !== currentNewestId
  );
}