diff --git a/src/backend/drivers/apps/AppDriver.js b/src/backend/drivers/apps/AppDriver.js index 4bb137018..1db8b1e45 100644 --- a/src/backend/drivers/apps/AppDriver.js +++ b/src/backend/drivers/apps/AppDriver.js @@ -862,14 +862,12 @@ export class AppDriver extends PuterDriver { * keeps resolving to the joined row. Mirrors v1 AppES's `#read` alias * plumbing. * - * The alias query is fired in parallel with the direct lookup so the common - * (no-alias) case pays only one round-trip. + * The alias is an uncached system KV read, so it waits for a direct miss. */ async #getByUidWithAlias(uid) { - const aliasPromise = this.#readCanonicalAppUidAlias(uid); const direct = await this.appStore.getByUid(uid); if (direct) return direct; - const canonicalUid = await aliasPromise; + const canonicalUid = await this.#readCanonicalAppUidAlias(uid); if ( typeof canonicalUid === 'string' && canonicalUid && diff --git a/src/backend/drivers/apps/AppDriver.test.ts b/src/backend/drivers/apps/AppDriver.test.ts index 0ed74ae36..41a18f340 100644 --- a/src/backend/drivers/apps/AppDriver.test.ts +++ b/src/backend/drivers/apps/AppDriver.test.ts @@ -371,6 +371,39 @@ describe('AppDriver.read', () => { withActor(actor, () => driver.read({ uid: 'app-nonexistent' })), ).rejects.toMatchObject({ statusCode: 404 }); }); + + it('reads the uid alias only when the direct lookup misses', async () => { + const { actor } = await makeUser(); + const created = await withActor(actor, () => + driver.create({ + object: { + name: uniqueName('alias-read'), + title: 't', + index_url: uniqueIndexUrl(), + }, + }), + ); + const kvGet = vi.spyOn(server.stores.kv, 'get'); + const aliasReads = () => + kvGet.mock.calls.filter((call) => + String((call[0] as { key?: string })?.key).startsWith( + 'app:canonicalUidAlias:', + ), + ).length; + try { + await withActor(actor, () => driver.read({ uid: created.uid })); + expect(aliasReads()).toBe(0); + + await expect( + withActor(actor, () => + driver.read({ uid: `app-${uuidv4()}` }), + ), + ).rejects.toMatchObject({ statusCode: 404 }); + expect(aliasReads()).toBe(1); + } finally { + kvGet.mockRestore(); + } + }); }); // ── select ──────────────────────────────────────────────────────────