Skip to content

Commit

Permalink
Report progress percent
Browse files Browse the repository at this point in the history
  • Loading branch information
dariober committed Nov 25, 2024
1 parent 6ebba39 commit a4c195b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ function serializeWords(foundWords: Iterable<[string, string]>): string[] {
export async function loadOboGraphJson(this: OntologyStore, db: Database) {
const startTime = Date.now()

this.options.update?.('Parsing JSON', 1)
let percent_progress = 1
this.options.update?.('Parsing JSON', percent_progress)
// TODO: using file streaming along with an event-based json parser
// instead of JSON.parse and .readFile could probably make this faster
// and less memory intensive
Expand All @@ -93,7 +94,9 @@ export async function loadOboGraphJson(this: OntologyStore, db: Database) {
} catch {
throw new Error('Error in loading ontology')
}
this.options.update?.('Parsing JSON complete', 10)

percent_progress += 5
this.options.update?.('Parsing JSON complete', percent_progress)

const parseTime = Date.now()

Expand All @@ -116,25 +119,46 @@ export async function loadOboGraphJson(this: OntologyStore, db: Database) {
const fullTextIndexPaths = getTextIndexFields
.call(this)
.map((def) => def.jsonPath)
for (const node of graph.nodes ?? []) {
if (isOntologyDBNode(node)) {
await nodeStore.add({
...node,
fullTextWords: serializeWords(
getWords(node, fullTextIndexPaths, this.prefixes),
),
})
if (graph.nodes) {
let last_progress = Math.round(percent_progress)
for (const [, node] of graph.nodes.entries()) {
percent_progress += 64 * (1 / graph.nodes.length)
if (
Math.round(percent_progress) != last_progress &&
percent_progress < 100
) {
this.options.update?.('Processing nodes', percent_progress)
last_progress = Math.round(percent_progress)
}
if (isOntologyDBNode(node)) {
await nodeStore.add({
...node,
fullTextWords: serializeWords(
getWords(node, fullTextIndexPaths, this.prefixes),
),
})
}
}
}

// load edges
const edgeStore = tx.objectStore('edges')
for (const edge of graph.edges ?? []) {
if (isOntologyDBEdge(edge)) {
await edgeStore.add(edge)
if (graph.edges) {
let last_progress = Math.round(percent_progress)
for (const [, edge] of graph.edges.entries()) {
percent_progress += 30 * (1 / graph.edges.length)
if (
Math.round(percent_progress) != last_progress &&
percent_progress < 100
) {
this.options.update?.('Processing edges', percent_progress)
last_progress = Math.round(percent_progress)
}
if (isOntologyDBEdge(edge)) {
await edgeStore.add(edge)
}
}
}

await tx.done

// record some metadata about this ontology and load operation
Expand Down
4 changes: 2 additions & 2 deletions packages/jbrowse-plugin-apollo/src/session/ClientDataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export function clientDataStoreFactory(
) as TextIndexFieldDefinition[],
]
if (!ontologyManager.findOntology(name)) {
// eslint-disable-next-line no-inner-declarations
const session = getSession(
self,
) as unknown as ApolloSessionModel
Expand All @@ -181,7 +180,7 @@ export function clientDataStoreFactory(
jobsManager.abortJob(job.name)
},
}
const update = (message: string, progress: number) => {
const update = (message: string, progress: number): void => {
if (progress === 0) {
jobsManager.runJob(job)
return
Expand All @@ -191,6 +190,7 @@ export function clientDataStoreFactory(
return
}
jobsManager.update(jobName, message, progress)
return
}
ontologyManager.addOntology(name, version, source, {
textIndexing: { indexFields },
Expand Down

0 comments on commit a4c195b

Please sign in to comment.