Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove locking from onEntities/RelationshipsFlushed #890

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,8 @@ export class FileSystemGraphObjectStore implements GraphObjectStore {
async flushEntitiesToDisk(
onEntitiesFlushed?: (entities: Entity[]) => Promise<void>,
) {
await this.lockOperation(() =>
pMap(
const entities = await this.lockOperation(() => {
return pMap(
this.localGraphObjectStore.collectEntitiesByStep(),
async ([stepId, entities]) => {
const indexable = entities.filter((e) => {
Expand Down Expand Up @@ -287,20 +287,21 @@ export class FileSystemGraphObjectStore implements GraphObjectStore {
}

this.localGraphObjectStore.flushEntities(entities);

if (onEntitiesFlushed) {
await onEntitiesFlushed(entities);
}
return entities;
},
),
);
);
});

if (onEntitiesFlushed) {
await Promise.all(entities.map(onEntitiesFlushed));
}
}

async flushRelationshipsToDisk(
onRelationshipsFlushed?: (relationships: Relationship[]) => Promise<void>,
) {
await this.lockOperation(() =>
pMap(
const relationships = await this.lockOperation(() => {
return pMap(
this.localGraphObjectStore.collectRelationshipsByStep(),
async ([stepId, relationships]) => {
const indexable = relationships.filter((r) => {
Expand Down Expand Up @@ -331,13 +332,14 @@ export class FileSystemGraphObjectStore implements GraphObjectStore {
}

this.localGraphObjectStore.flushRelationships(relationships);

if (onRelationshipsFlushed) {
await onRelationshipsFlushed(relationships);
}
return relationships;
},
),
);
);
});

if (onRelationshipsFlushed) {
await Promise.all(relationships.map(onRelationshipsFlushed));
}
}

getIndexMetadataForGraphObjectType({
Expand Down Expand Up @@ -379,7 +381,7 @@ export class FileSystemGraphObjectStore implements GraphObjectStore {
private async lockOperation<T>(operation: () => Promise<T>) {
await this.semaphore.acquire();
try {
await operation();
return await operation();
} finally {
this.semaphore.release();
}
Expand Down