Skip to content

Commit

Permalink
Remove node fibers
Browse files Browse the repository at this point in the history
Ref: node fibers #145
  • Loading branch information
maxkfranz committed Dec 2, 2024
1 parent 230f449 commit a4c33dc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 71 deletions.
37 changes: 0 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@
"elasticsearch": "^15.4.1",
"esm": "^3.2.22",
"express": "^4.13.4",
"fibers": "^5.0.0",
"ftp": "^0.3.10",
"lodash": "^4.17.11",
"morgan": "^1.7.0",
Expand Down
34 changes: 17 additions & 17 deletions src/server/datasource/aggregate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import _ from 'lodash';
import ROOT_STRAINS from './strains/root';
import { getOrganismById } from './organisms';
import { MAX_SEARCH_WS, MAX_FUZZ_ES } from '../config';
import Future from 'fibers/future';

const ROOT_STRAIN_ORGS = Object.values(ROOT_STRAINS).map(getOrganismById);
const isRootStrainOrgId = id => ROOT_STRAIN_ORGS.some(org => org.is(id));
Expand Down Expand Up @@ -63,32 +62,33 @@ const search = function(searchString, namespace = ['ncbi', 'chebi', 'fplx'], org
});
};

const doStrainFilter = ents => {
let task = Future.wrap(function(args, next){ // code in this block runs in its own thread
let res = filterStrains(args.ents);
let err = null;

next( err, res );
const doStrainFilter = (ents) => {
return new Promise((resolve, reject) => {
try {
const res = filterStrains(ents);
resolve(res);
} catch (err) {
reject(err);
}
});

return task({ ents }).promise();
};

const doSearches = () => {
const join = ress => _.uniqWith(_.concat(...ress), (ent1, ent2) => {
return ent1.namespace === ent2.namespace && ent1.id === ent2.id;
});

const doJoin = ress => {
let task = Future.wrap(function(args, next){ // code in this block runs in its own thread
let res = join(args.ress);
let err = null;

next( err, res );
const doJoin = (ress) => {
return new Promise((resolve, reject) => {
try {
const res = join(ress);
resolve(res);
} catch (err) {
reject(err);
}
});

return task({ ress }).promise();
};


if( searchString.length === 1 ){
return doSearch(0);
Expand Down
15 changes: 7 additions & 8 deletions src/server/datasource/processing.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
/** @module processing */
import Future from 'fibers/future';
import _ from 'lodash';

import { db } from '../db';
import logger from '../logger';
import { CHUNK_SIZE, MAX_SIMULT_CHUNKS } from '../config';

const processChunk = (chunk, processEntry) => {
let task = Future.wrap(function(chunk, next){ // code in this block runs in its own thread
let processedEntries = chunk.map(processEntry);
let err = null;

next( err, processedEntries );
return new Promise((resolve, reject) => {
try {
const processedEntries = chunk.map(processEntry);
resolve(processedEntries);
} catch (err) {
reject(err);
}
});

return task(chunk).promise();
};

/**
Expand Down
16 changes: 8 additions & 8 deletions src/server/datasource/rank.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import _ from 'lodash';
import { getOrganismIndex, getDefaultOrganismIndex } from './organisms';
import dice from 'dice-coefficient'; // sorensen dice coeff
import Future from 'fibers/future';
import { sanitizeNameForCmp as sanitize } from '../util';

const DISTANCE_FIELDS = ['name', 'synonyms']; // TODO should share list with db.js
Expand Down Expand Up @@ -120,13 +119,14 @@ export const rank = (ents, searchTerm, organismOrdering) => {
};

export const rankInThread = (ents, searchTerm, organismOrdering) => {
let task = Future.wrap(function(args, next){ // code in this block runs in its own thread
let res = rank(args.ents, args.searchTerm, args.organismOrdering);
let err = null;

next( err, res );
// TODO put back in separate thread if necessary in future
return new Promise((resolve, reject) => {
try {
const res = rank(ents, searchTerm, organismOrdering);
resolve(res);
} catch (err) {
reject(err);
}
});

return task({ ents, searchTerm, organismOrdering }).promise();
};

0 comments on commit a4c33dc

Please sign in to comment.