diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index 55255f13ee..490b41eabb 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -84,7 +84,7 @@ class ClientImpl implements Client { query: DocumentQuery, options?: FindOptions ): Promise | undefined> { - return (await this.findAll(_class, query, options))[0] + return (await this.findAll(_class, query, { ...options, limit: 1 }))[0] } async tx (tx: Tx): Promise { diff --git a/packages/core/src/operations.ts b/packages/core/src/operations.ts index 03cc2551d4..8e272fa2d7 100644 --- a/packages/core/src/operations.ts +++ b/packages/core/src/operations.ts @@ -35,8 +35,8 @@ export class TxOperations implements Omit { return this.client.findAll(_class, query, options) } - async findOne (_class: Ref>, query: DocumentQuery, options?: FindOptions | undefined): Promise | undefined> { - return (await this.findAll(_class, query, options))[0] + findOne (_class: Ref>, query: DocumentQuery, options?: FindOptions | undefined): Promise | undefined> { + return this.client.findOne(_class, query, options) } tx (tx: Tx): Promise { diff --git a/packages/query/src/index.ts b/packages/query/src/index.ts index 1fda1aac1d..9d485944b2 100644 --- a/packages/query/src/index.ts +++ b/packages/query/src/index.ts @@ -109,7 +109,7 @@ export class LiveQuery extends TxProcessor implements Client { query: DocumentQuery, options?: FindOptions ): Promise | undefined> { - return (await this.findAll(_class, query, options))[0] + return await this.client.findOne(_class, query, options) } query( @@ -285,7 +285,7 @@ export class LiveQuery extends TxProcessor implements Client { for (const key in lookup) { const _class = (lookup as any)[key] as Ref> const _id = (doc as any)[key] as Ref - ;(result as any)[key] = (await this.client.findAll(_class, { _id }))[0] + ;(result as any)[key] = await this.client.findOne(_class, { _id }) } ;(doc as WithLookup).$lookup = result } diff --git a/plugins/workbench-resources/src/components/Workbench.svelte b/plugins/workbench-resources/src/components/Workbench.svelte index c22ebaa34e..fa2926269f 100644 --- a/plugins/workbench-resources/src/components/Workbench.svelte +++ b/plugins/workbench-resources/src/components/Workbench.svelte @@ -56,7 +56,7 @@ onDestroy( location.subscribe(async (loc) => { currentApp = loc.path[1] as Ref - currentApplication = (await client.findAll(workbench.class.Application, { _id: currentApp }))[0] + currentApplication = await client.findOne(workbench.class.Application, { _id: currentApp }) navigatorModel = currentApplication?.navigatorModel const currentFolder = loc.path[2] as Ref ownSpecialComponent = getOwnSpecialComponent(currentFolder) @@ -71,7 +71,7 @@ return } - const space = (await client.findAll(core.class.Space, { _id: currentFolder }))[0] + const space = await client.findOne(core.class.Space, { _id: currentFolder }) currentSpace = currentFolder if (space) { const spaceClass = client.getHierarchy().getClass(space._class) // (await client.findAll(core.class.Class, { _id: space._class }))[0]