Skip to content

Commit

Permalink
fix: queries for proposals (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
baiirun authored Jan 10, 2025
1 parent 1011dba commit 5de4402
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
4 changes: 2 additions & 2 deletions apps/web/core/io/subgraph/fetch-entities-batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ export async function fetchEntitiesBatch(
const decodedSpace = Schema.decodeEither(SubstreamEntity)(e);

return Either.match(decodedSpace, {
onLeft: error => {
console.error(`Unable to decode collection item entity ${e.id} with error ${error}`);
onLeft: () => {
// console.error(`Unable to decode collection item entity ${e.id} with error ${error}`);
return null;
},
onRight: substreamEntity => {
Expand Down
22 changes: 16 additions & 6 deletions apps/web/core/utils/change/change.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Proposal } from '~/core/io/dto/proposals';
import { Version } from '~/core/io/dto/versions';
import { EntityId } from '~/core/io/schema';
import { fetchEntity } from '~/core/io/subgraph';
import { fetchEntitiesBatch } from '~/core/io/subgraph/fetch-entities-batch';
import { fetchVersion } from '~/core/io/subgraph/fetch-version';
import { fetchVersionsBatch } from '~/core/io/subgraph/fetch-versions-batch';
import { queryClient } from '~/core/query-client';
Expand Down Expand Up @@ -96,9 +97,7 @@ export async function fromActiveProposal(proposal: Proposal): Promise<EntityChan
const versionsByEditId = await fetchVersionsByEditId({ editId: proposal.editId });

// Version entity ids are mapped to the version.id
const currentVersionsForEntityIds = await fetchVersionsBatch({
versionIds: versionsByEditId.map(v => v.versionId),
});
const currentVersionsForEntityIds = await fetchEntitiesBatch(versionsByEditId.map(v => v.id));

return aggregateChanges({
spaceId: proposal.space.id,
Expand All @@ -110,9 +109,20 @@ export async function fromActiveProposal(proposal: Proposal): Promise<EntityChan
export async function fromEndedProposal(proposal: Proposal): Promise<EntityChange[]> {
const versionsByEditId = await fetchVersionsByEditId({ editId: proposal.editId });

const previousVersions = await fetchVersionsBatch({
versionIds: versionsByEditId.map(v => v.versionId),
});
// const previousVersions = await fetchVersionsBatch({
// versionIds: versionsByEditId.map(v => v.versionId),
// });

// We should batch this but not sure the easiest way to do it in a single query
const previousVersions = await Promise.all(
versionsByEditId.map(v =>
fetchPreviousVersionByCreatedAt({
createdAt: proposal.createdAt,
entityId: v.id,
spaceId: proposal.space.id,
})
)
);

return aggregateChanges({
spaceId: proposal.space.id,
Expand Down

0 comments on commit 5de4402

Please sign in to comment.