Revert the timeline optimistic and pagination rework (#2596)
* Add npm release track invariant and beta dist-tag procedure * Revert "Keep older chat history and image previews stable (#2490)" The timeline optimistic/pagination rework needs more work than main releases can wait for. Reverted together with #2484; both are reapplied on integration/timeline-optimistic-rework. * Revert "Stop completed turns from appearing stuck (#2484)" See the #2490 revert. #2490 built on this submission-authority change, so the two revert and reapply as a pair.
This commit is contained in:
@@ -1,40 +1,5 @@
|
||||
import { collectRetainedAttachmentIds } from "@/attachments/gc-retention";
|
||||
import type { AttachmentMetadata } from "@/attachments/types";
|
||||
import { getAttachmentStore } from "@/attachments/store";
|
||||
import type { AttachmentMetadata, SaveAttachmentInput } from "@/attachments/types";
|
||||
|
||||
const activePersistence = new Set<Promise<AttachmentMetadata>>();
|
||||
const persistedDuringGarbageCollection = new Set<string>();
|
||||
let pendingGarbageCollections = 0;
|
||||
let garbageCollectionTail: Promise<void> = Promise.resolve();
|
||||
let persistenceBarrier: Promise<void> | null = null;
|
||||
let releasePersistenceBarrier: (() => void) | null = null;
|
||||
|
||||
async function waitForPersistenceBarrier(): Promise<void> {
|
||||
const barrier = persistenceBarrier;
|
||||
if (!barrier) {
|
||||
return;
|
||||
}
|
||||
await barrier;
|
||||
await waitForPersistenceBarrier();
|
||||
}
|
||||
|
||||
async function persistAttachment(input: SaveAttachmentInput): Promise<AttachmentMetadata> {
|
||||
await waitForPersistenceBarrier();
|
||||
const pending = (async () => {
|
||||
const store = await getAttachmentStore();
|
||||
const attachment = await store.save(input);
|
||||
if (pendingGarbageCollections > 0) {
|
||||
persistedDuringGarbageCollection.add(attachment.id);
|
||||
}
|
||||
return attachment;
|
||||
})();
|
||||
activePersistence.add(pending);
|
||||
try {
|
||||
return await pending;
|
||||
} finally {
|
||||
activePersistence.delete(pending);
|
||||
}
|
||||
}
|
||||
|
||||
export async function persistAttachmentFromBlob(input: {
|
||||
blob: Blob;
|
||||
@@ -42,7 +7,8 @@ export async function persistAttachmentFromBlob(input: {
|
||||
fileName?: string | null;
|
||||
id?: string;
|
||||
}): Promise<AttachmentMetadata> {
|
||||
return await persistAttachment({
|
||||
const store = await getAttachmentStore();
|
||||
return await store.save({
|
||||
id: input.id,
|
||||
mimeType: input.mimeType,
|
||||
fileName: input.fileName,
|
||||
@@ -56,7 +22,8 @@ export async function persistAttachmentFromDataUrl(input: {
|
||||
fileName?: string | null;
|
||||
id?: string;
|
||||
}): Promise<AttachmentMetadata> {
|
||||
return await persistAttachment({
|
||||
const store = await getAttachmentStore();
|
||||
return await store.save({
|
||||
id: input.id,
|
||||
mimeType: input.mimeType,
|
||||
fileName: input.fileName,
|
||||
@@ -70,7 +37,8 @@ export async function persistAttachmentFromBytes(input: {
|
||||
fileName?: string | null;
|
||||
id?: string;
|
||||
}): Promise<AttachmentMetadata> {
|
||||
return await persistAttachment({
|
||||
const store = await getAttachmentStore();
|
||||
return await store.save({
|
||||
id: input.id,
|
||||
mimeType: input.mimeType,
|
||||
fileName: input.fileName,
|
||||
@@ -84,7 +52,8 @@ export async function persistAttachmentFromFileUri(input: {
|
||||
fileName?: string | null;
|
||||
id?: string;
|
||||
}): Promise<AttachmentMetadata> {
|
||||
return await persistAttachment({
|
||||
const store = await getAttachmentStore();
|
||||
return await store.save({
|
||||
id: input.id,
|
||||
mimeType: input.mimeType,
|
||||
fileName: input.fileName,
|
||||
@@ -164,41 +133,6 @@ export async function deleteAttachments(
|
||||
export async function garbageCollectAttachments(input: {
|
||||
referencedIds: ReadonlySet<string>;
|
||||
}): Promise<void> {
|
||||
pendingGarbageCollections += 1;
|
||||
if (!persistenceBarrier) {
|
||||
persistenceBarrier = new Promise<void>((resolve) => {
|
||||
releasePersistenceBarrier = resolve;
|
||||
});
|
||||
}
|
||||
|
||||
const previousGarbageCollection = garbageCollectionTail;
|
||||
const currentGarbageCollection = (async () => {
|
||||
await previousGarbageCollection;
|
||||
while (activePersistence.size > 0) {
|
||||
await Promise.allSettled(activePersistence);
|
||||
}
|
||||
const referencedIds = new Set(input.referencedIds);
|
||||
for (const id of collectRetainedAttachmentIds()) {
|
||||
referencedIds.add(id);
|
||||
}
|
||||
for (const id of persistedDuringGarbageCollection) {
|
||||
referencedIds.add(id);
|
||||
}
|
||||
const store = await getAttachmentStore();
|
||||
await store.garbageCollect({ referencedIds });
|
||||
})();
|
||||
garbageCollectionTail = currentGarbageCollection.catch(() => undefined);
|
||||
|
||||
try {
|
||||
await currentGarbageCollection;
|
||||
} finally {
|
||||
pendingGarbageCollections -= 1;
|
||||
if (pendingGarbageCollections === 0) {
|
||||
persistedDuringGarbageCollection.clear();
|
||||
const release = releasePersistenceBarrier;
|
||||
releasePersistenceBarrier = null;
|
||||
persistenceBarrier = null;
|
||||
release?.();
|
||||
}
|
||||
}
|
||||
const store = await getAttachmentStore();
|
||||
await store.garbageCollect({ referencedIds: input.referencedIds });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user