feat(perf): implement performance optimizations for session handling

- Introduced a new configuration file `config.yaml` for specifying project context and artifact rules.
- Added `.openspec.yaml` files for tracking changes related to performance improvements.
- Created design documents outlining the context, goals, decisions, and migration plans for optimizing session performance.
- Proposed changes include batching database queries, debouncing event refreshes, purging old events, and implementing loading states for better user experience.
- Added tasks and specifications to ensure proper implementation and validation of the new features.

These enhancements aim to improve the scalability and responsiveness of the application during collaborative sessions.
This commit is contained in:
2026-03-10 08:06:47 +01:00
parent 6baa9bfada
commit 2d266f89f9
19 changed files with 519 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
## ADDED Requirements
### Requirement: Paginated sessions list
The sessions page SHALL load sessions in pages rather than fetching all sessions at once, with a default page size of 20 per workshop type.
#### Scenario: Initial load shows first page
- **WHEN** a user visits the sessions page
- **THEN** at most 20 sessions per workshop type SHALL be loaded
- **THEN** a total count SHALL be displayed (e.g., "Showing 20 of 47")
#### Scenario: Load more sessions on demand
- **WHEN** there are more sessions beyond the current page
- **THEN** a "Charger plus" button SHALL be displayed
- **WHEN** the user clicks "Charger plus"
- **THEN** the next page of sessions SHALL be appended to the list

View File

@@ -0,0 +1,17 @@
## ADDED Requirements
### Requirement: Single polling interval per active session
The SSE infrastructure SHALL maintain at most one active DB polling interval per session, regardless of the number of connected clients.
#### Scenario: First client connects starts polling
- **WHEN** the first client connects to a session's SSE endpoint
- **THEN** a single polling interval SHALL be started for that session
#### Scenario: Additional clients share existing polling
- **WHEN** a second or subsequent client connects to the same session's SSE endpoint
- **THEN** no additional polling interval SHALL be created
- **THEN** the new client SHALL receive events from the shared poll
#### Scenario: Last client disconnect stops polling
- **WHEN** all clients disconnect from a session's SSE endpoint
- **THEN** the polling interval for that session SHALL be stopped and cleaned up

View File

@@ -0,0 +1,22 @@
## ADDED Requirements
### Requirement: Centralized broadcast module
The system SHALL provide a centralized `src/lib/broadcast.ts` module used by all workshop SSE routes to push events to connected clients.
#### Scenario: Server Action triggers broadcast
- **WHEN** a Server Action mutates session data and calls `broadcast(sessionId, event)`
- **THEN** all clients subscribed to that session SHALL receive the event immediately without waiting for the next poll cycle
#### Scenario: Broadcast module subscribe/unsubscribe
- **WHEN** an SSE route calls `subscribe(sessionId, callback)`
- **THEN** the callback SHALL be invoked on every subsequent `broadcast(sessionId, ...)` call
- **WHEN** the returned `unsubscribe()` function is called
- **THEN** the callback SHALL no longer receive events
### Requirement: Granular cache invalidation via revalidateTag
Server Actions SHALL use `revalidateTag` with session-scoped tags instead of `revalidatePath` to limit cache invalidation scope.
#### Scenario: Session mutation invalidates only that session's cache
- **WHEN** a Server Action mutates a specific session (e.g., adds an item)
- **THEN** only the cache tagged `session:<id>` SHALL be invalidated
- **THEN** other sessions' cached data SHALL NOT be invalidated