Skip to content

Commit

Permalink
feat: update for better clause
Browse files Browse the repository at this point in the history
  • Loading branch information
ponderingdemocritus committed Oct 2, 2024
1 parent 0530d74 commit 70f75f8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/state/src/recs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ import { convertValues } from "../utils";
export const getSyncEntities = async <S extends Schema>(
client: ToriiClient,
components: Component<S, Metadata, undefined>[],
clause: Clause | undefined,
entityKeyClause: EntityKeysClause[],
limit: number = 100
) => {
await getEntities(client, components, limit);
await getEntities(client, clause, components, limit);
return await syncEntities(client, components, entityKeyClause);
};

Expand Down Expand Up @@ -103,21 +104,22 @@ export const getSyncEvents = async <S extends Schema>(
*/
export const getEntities = async <S extends Schema>(
client: ToriiClient,
clause: Clause | undefined,
components: Component<S, Metadata, undefined>[],
limit: number = 100
) => {
let cursor = 0;
let offset = 0;
let continueFetching = true;

while (continueFetching) {
const entities = await client.getAllEntities(limit, cursor);
const entities = await client.getEntities({ limit, offset, clause });

setEntities(entities, components);

if (Object.keys(entities).length < limit) {
continueFetching = false;
} else {
cursor += limit;
offset += limit;
}
}
};
Expand Down

0 comments on commit 70f75f8

Please sign in to comment.