Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve boot time by implementing sliding sync #2290

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d137242
Improve boot time by implementing sliding sync
FadhlanR Mar 14, 2025
f9145a9
Fix host tests
FadhlanR Mar 17, 2025
f764fe5
revert mock MatrixEvent
FadhlanR Mar 17, 2025
d881f31
wait until all events consumed
FadhlanR Mar 17, 2025
843d928
Fix host tests
FadhlanR Mar 17, 2025
17e3a7c
set m.direct
FadhlanR Mar 18, 2025
06438a4
Another sdk patch
FadhlanR Mar 18, 2025
1d34114
lint fix
FadhlanR Mar 18, 2025
c1401d4
Load more rooms if needed
FadhlanR Mar 18, 2025
9cb49b5
Merge branch 'main' into cs-7985-implement-sliding-sync
FadhlanR Mar 18, 2025
a6e4ab3
Add test to load more rooms
FadhlanR Mar 18, 2025
52ce61f
lint fix
FadhlanR Mar 18, 2025
1576b13
Fix host tests
FadhlanR Mar 19, 2025
f127c9d
Merge branch 'main' into cs-7985-implement-sliding-sync
FadhlanR Mar 19, 2025
8c5705e
Execute loadAlltimelineEvents once at a time
FadhlanR Mar 19, 2025
bbbfed9
Update _client and _sliding-sync
FadhlanR Mar 20, 2025
9020bf4
Revert unnecessary updates
FadhlanR Mar 20, 2025
22723e3
Merge branch 'main' into cs-7985-implement-sliding-sync
FadhlanR Mar 20, 2025
5aa449b
Remove unnecessary disabled
FadhlanR Mar 20, 2025
b42d1d4
Wait for take percySnapshot
FadhlanR Mar 20, 2025
8bce43f
Update based on feedbacks
FadhlanR Mar 21, 2025
682d7ff
Revert unnecassry changes
FadhlanR Mar 21, 2025
b881a4b
Merge branch 'main' into cs-7985-implement-sliding-sync
FadhlanR Mar 21, 2025
6b6f0ea
Use roomResource.processing
FadhlanR Mar 21, 2025
d01bf2b
Simplified wait for event to be loaded
FadhlanR Mar 23, 2025
a14c957
Merge branch 'main' into cs-7985-implement-sliding-sync
FadhlanR Mar 23, 2025
a4fe8c9
revert instance updates
FadhlanR Mar 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ export default class PastSessionItem extends Component<Signature> {
}

get isStreaming() {
if (!this.args.session.lastMessage) {
return false;
}
return !this.args.session.lastMessage.isStreamingFinished;
return this.args.session.lastMessage?.isStreamingFinished === false;
}

get hasUnseenMessage() {
Expand Down
146 changes: 98 additions & 48 deletions packages/host/app/components/ai-assistant/past-sessions.gts
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import type { TemplateOnlyComponent } from '@ember/component/template-only';
import { on } from '@ember/modifier';
import { service } from '@ember/service';
import Component from '@glimmer/component';

import { IconButton } from '@cardstack/boxel-ui/components';
import { modifier } from 'ember-modifier';

import { IconButton, LoadingIndicator } from '@cardstack/boxel-ui/components';
import { DropdownArrowFilled } from '@cardstack/boxel-ui/icons';

import { SessionRoomData } from './panel';
import AiAssistantPanelPopover from './panel-popover';
import PastSessionItem, { type RoomActions } from './past-session-item';

import type MatrixService from '../../services/matrix-service';

interface Signature {
Args: {
sessions: SessionRoomData[];
Expand All @@ -17,51 +22,96 @@ interface Signature {
Element: HTMLElement;
}

const AiAssistantPastSessionsList: TemplateOnlyComponent<Signature> = <template>
<AiAssistantPanelPopover
@onClose={{@onClose}}
data-test-past-sessions
...attributes
>
<:header>
All Sessions
<IconButton
@icon={{DropdownArrowFilled}}
@width='12px'
@height='12px'
{{on 'click' @onClose}}
aria-label='Close Past Sessions'
data-test-close-past-sessions
/>
</:header>
<:body>
{{#if @sessions}}
<ul class='past-sessions'>
{{#each @sessions key='roomId' as |session|}}
<PastSessionItem @session={{session}} @actions={{@roomActions}} />
{{/each}}
</ul>
{{else}}
<div class='empty-collection'>
No past sessions to show.
</div>
{{/if}}
</:body>
</AiAssistantPanelPopover>
export default class AiAssistantPastSessionsList extends Component<Signature> {
@service declare matrixService: MatrixService;

checkScroll = modifier((element: HTMLElement) => {
let checkScrollPosition = () => {
let { scrollHeight, scrollTop, clientHeight } = element;
let isAtBottom = Math.abs(scrollHeight - scrollTop - clientHeight) < 1;
let hasNoScroll = scrollHeight <= clientHeight;

if (isAtBottom || hasNoScroll) {
this.matrixService.loadMoreAIRooms();
}
};

<style scoped>
.past-sessions {
list-style-type: none;
padding: 0;
margin: 0;
margin-bottom: var(--boxel-sp-xs);
}
.empty-collection {
padding: var(--boxel-sp-sm);
text-align: center;
color: var(--boxel-450);
}
</style>
</template>;
checkScrollPosition();

export default AiAssistantPastSessionsList;
element.addEventListener('scroll', checkScrollPosition);

return () => {
element.removeEventListener('scroll', checkScrollPosition);
};
});

<template>
<AiAssistantPanelPopover
@onClose={{@onClose}}
data-test-past-sessions
...attributes
>
<:header>
All Sessions
<IconButton
@icon={{DropdownArrowFilled}}
@width='12px'
@height='12px'
{{on 'click' @onClose}}
aria-label='Close Past Sessions'
data-test-close-past-sessions
/>
</:header>
<:body>
{{#if @sessions}}
<ul class='past-sessions' {{this.checkScroll}}>
{{#each @sessions key='roomId' as |session|}}
<PastSessionItem @session={{session}} @actions={{@roomActions}} />
{{/each}}
{{#if this.matrixService.isLoadingMoreAIRooms}}
<li
class='loading-indicator-container'
data-test-loading-more-rooms
>
<LoadingIndicator
@color='var(--boxel-dark)'
class='loading-indicator'
/>
</li>
{{/if}}
</ul>
{{else}}
<div class='empty-collection'>
No past sessions to show.
</div>
{{/if}}
</:body>
</AiAssistantPanelPopover>

<style scoped>
.past-sessions {
list-style-type: none;
padding: 0;
margin: 0;
margin-bottom: var(--boxel-sp-xs);
max-height: 400px;
overflow-y: auto;
}
.empty-collection {
padding: var(--boxel-sp-sm);
text-align: center;
color: var(--boxel-450);
}
.loading-indicator-container {
padding: var(--boxel-sp-sm);
text-align: center;
display: flex;
justify-content: center;
align-items: center;
}
.loading-indicator {
margin: 0 auto;
}
</style>
</template>
}
32 changes: 26 additions & 6 deletions packages/host/app/components/matrix/room.gts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import { TrackedObject, TrackedSet } from 'tracked-built-ins';

import { v4 as uuidv4 } from 'uuid';

import { BoxelButton } from '@cardstack/boxel-ui/components';
import { eq, not } from '@cardstack/boxel-ui/helpers';
import { BoxelButton, LoadingIndicator } from '@cardstack/boxel-ui/components';
import { and, eq, not } from '@cardstack/boxel-ui/helpers';

import {
type getCard,
Expand Down Expand Up @@ -87,8 +87,14 @@ export default class Room extends Component<Signature> {
{{#if (not this.doMatrixEventFlush.isRunning)}}
<section
class='room'
data-room-settled={{this.doWhenRoomChanges.isIdle}}
data-test-room-settled={{this.doWhenRoomChanges.isIdle}}
data-room-settled={{(and
this.doWhenRoomChanges.isIdle
(not this.matrixService.isLoadingTimeline)
)}}
data-test-room-settled={{(and
this.doWhenRoomChanges.isIdle
(not this.matrixService.isLoadingTimeline)
)}}
data-test-room-name={{@roomResource.name}}
data-test-room={{@roomId}}
>
Expand All @@ -109,7 +115,14 @@ export default class Room extends Component<Signature> {
data-test-message-idx={{i}}
/>
{{else}}
<NewSession @sendPrompt={{this.sendMessage}} />
{{#if this.matrixService.isLoadingTimeline}}
<LoadingIndicator
@color='var(--boxel-light)'
class='loading-indicator'
/>
{{else}}
<NewSession @sendPrompt={{this.sendMessage}} />
{{/if}}
{{/each}}
{{#if this.room}}
{{#if this.showUnreadIndicator}}
Expand Down Expand Up @@ -218,6 +231,12 @@ export default class Room extends Component<Signature> {
:deep(.ai-assistant-conversation > *:nth-last-of-type(2)) {
padding-bottom: var(--boxel-sp-xl);
}
.loading-indicator {
margin-top: auto;
margin-bottom: auto;
margin-left: auto;
margin-right: auto;
}
</style>
</template>

Expand Down Expand Up @@ -805,7 +824,8 @@ export default class Room extends Component<Signature> {
this.autoAttachedCards.size !== 0,
) &&
!!this.room &&
!this.messages.some((m) => this.isPendingMessage(m))
!this.messages.some((m) => this.isPendingMessage(m)) &&
!this.matrixService.isLoadingTimeline
);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/host/app/services/matrix-sdk-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Service from '@ember/service';
import { service } from '@ember/service';

import * as MatrixSDK from 'matrix-js-sdk';
import { SlidingSync } from 'matrix-js-sdk/lib/sliding-sync';

import { RealmAuthClient } from '@cardstack/runtime-common/realm-auth-client';

Expand All @@ -23,6 +24,11 @@ export default class MatrixSDKLoader extends Service {
}
return this.#extended;
}

// For testing purposes, we need to mock the SlidingSync class
get SlidingSync() {
return SlidingSync;
}
}

export class ExtendedMatrixSDK {
Expand Down
Loading