From 6e3451abb82b7b834438e7a030e02efcdbcc495e Mon Sep 17 00:00:00 2001 From: Matt <1009003+tantaman@users.noreply.github.com> Date: Fri, 8 Dec 2023 16:21:14 -0500 Subject: [PATCH] track old value ourselves --- client/src/issue/issue.ts | 12 ------------ client/src/materialite/db.ts | 15 ++++++++------- 2 files changed, 8 insertions(+), 19 deletions(-) diff --git a/client/src/issue/issue.ts b/client/src/issue/issue.ts index 53bddeb..3728245 100644 --- a/client/src/issue/issue.ts +++ b/client/src/issue/issue.ts @@ -54,15 +54,3 @@ export async function getIssueComments( return commentSchema.parse(val); }); } - -const REVERSE_TIMESTAMP_LENGTH = Number.MAX_SAFE_INTEGER.toString().length; - -export function reverseTimestampSortKey(timestamp: number, id: string): string { - return ( - Math.floor(Number.MAX_SAFE_INTEGER - timestamp) - .toString() - .padStart(REVERSE_TIMESTAMP_LENGTH, '0') + - '-' + - id - ); -} diff --git a/client/src/materialite/db.ts b/client/src/materialite/db.ts index 9bcfbb0..c0ddbc9 100644 --- a/client/src/materialite/db.ts +++ b/client/src/materialite/db.ts @@ -43,18 +43,22 @@ const issueComparators = Object.fromEntries( }), ) as Record number>; -// We could build the indices on the fly when the user selects a given ordering. -// Creating all the orderings up front for now. +/** + * Maintains base collection and indices for issues + */ class IssueCollection { readonly #orderedIndices = new Map>(); + readonly #base = m.newUnorderedSet((issue: Issue) => issue.id); add(issue: Issue) { + this.#base.add(issue); for (const index of this.#orderedIndices.values()) { index.add(issue); } } delete(issue: Issue) { + this.#base.delete(issue); for (const index of this.#orderedIndices.values()) { index.delete(issue); } @@ -70,11 +74,8 @@ class IssueCollection { index = m.newSortedSet(issueComparators[order]); const newIndex = index; m.tx(() => { - const existingIndex = [...this.#orderedIndices.values()][0]; - if (existingIndex) { - for (const issue of existingIndex.value) { - newIndex.add(issue); - } + for (const issue of this.#base.value.values()) { + newIndex.add(issue); } }); this.#orderedIndices.set(order, index);