Skip to content

Commit

Permalink
chore: refactor file locking to utils package
Browse files Browse the repository at this point in the history
  • Loading branch information
NeuralFlux committed Nov 5, 2024
1 parent 671e4d4 commit 23d3010
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
"@biothings-explorer/call-apis": "workspace:../call-apis",
"@biothings-explorer/node-expansion": "workspace:../node-expansion",
"@biothings-explorer/smartapi-kg": "workspace:../smartapi-kg",
"@biothings-explorer/utils": "workspace:../utils",
"@biothings-explorer/types": "workspace:../types",
"biolink-model": "workspace:../biolink-model",
"biomedical_id_resolver": "workspace:../biomedical_id_resolver",
"@biothings-explorer/utils": "workspace:../utils",
"@sentry/node": "^7.74.1",
"async": "^3.2.4",
"biolink-model": "workspace:../biolink-model",
"biomedical_id_resolver": "workspace:../biomedical_id_resolver",
"chi-square-p-value": "^1.0.5",
"debug": "^4.3.4",
"ioredis": "^5.3.2",
Expand Down
14 changes: 6 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Graph from './graph/graph';
import EdgeManager from './edge_manager';
import _ from 'lodash';
import QEdge2APIEdgeHandler from './qedge2apiedge';
import { LogEntry, StampedLog } from '@biothings-explorer/utils';
import { lockWithActionAsync, LogEntry, StampedLog } from '@biothings-explorer/utils';
import { promises as fs } from 'fs';
import { getDescendants } from '@biothings-explorer/node-expansion';
import { resolveSRI, SRINodeNormFailure } from 'biomedical_id_resolver';
Expand Down Expand Up @@ -81,8 +81,11 @@ export default class TRAPIQueryHandler {
if (this.options.smartapi) {
smartapiRegistry = this.options.smartapi;
} else {
const file = await fs.readFile(this.path, 'utf-8');
smartapiRegistry = JSON.parse(file);
smartapiRegistry = await lockWithActionAsync(this.path, async () => {
const file = await fs.readFile(this.path, 'utf-8');
const hits = JSON.parse(file);
return hits;
}, debug);
}

const smartapiIds: string[] = [];
Expand Down Expand Up @@ -722,12 +725,7 @@ export default class TRAPIQueryHandler {
return;
}
debug('MetaKG successfully loaded!');
const filteredOps = metaKG.ops.filter(op =>
op.association.qualifiers &&
Object.values(op.association.qualifiers).some(value => Array.isArray(value))
)
span1?.finish();
// metaKG.ops = filteredOps;

if (global.missingAPIs) {
this.logs.push(
Expand Down

0 comments on commit 23d3010

Please sign in to comment.