Skip to content

Commit

Permalink
Add maximum number of persisted chat sessions (#180775)
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens authored Apr 25, 2023
1 parent 7a4d55a commit 2902f27
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ export class InteractiveSessionModel extends Disposable implements IInteractiveS
}

private _creationDate: number;
get creationDate(): number {
return this._creationDate;
}

constructor(
public readonly providerId: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ type InteractiveSessionTerminalClassification = {
comment: 'Provides insight into the usage of InteractiveSession features.';
};

const maxPersistedSessions = 20;

export class InteractiveSessionService extends Disposable implements IInteractiveSessionService {
declare _serviceBrand: undefined;

Expand Down Expand Up @@ -145,6 +147,8 @@ export class InteractiveSessionService extends Disposable implements IInteractiv
.filter(session => session.getRequests().length > 0);
allSessions = allSessions.concat(
Object.values(this._persistedSessions).filter(session => session.requests.length));
allSessions.sort((a, b) => (b.creationDate ?? 0) - (a.creationDate ?? 0));
allSessions = allSessions.slice(0, maxPersistedSessions);
this.trace('onWillSaveState', `Persisting ${allSessions.length} sessions`);

const serialized = JSON.stringify(allSessions);
Expand Down

0 comments on commit 2902f27

Please sign in to comment.