Skip to content

Commit ff0c569

Browse files
Get sequence up front if possible when checking
1 parent 3bc6524 commit ff0c569

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

packages/apollo-collaboration-server/src/checks/checks.service.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,26 @@ export class ChecksService {
108108
if (!c) {
109109
throw new Error(`Check "${check.name}" not registered`)
110110
}
111-
const result = await c.checkFeature(
112-
flatDoc,
113-
(start: number, end: number) => {
111+
// If the feature is small enough, just fetch its sequence once and
112+
// substring that to avoid slow disk reads
113+
let featureSequence: string | undefined
114+
if (doc.max - doc.min <= 1_000_000) {
115+
featureSequence = await this.getSequence({
116+
start: doc.min,
117+
end: doc.max,
118+
featureDoc: doc,
119+
})
120+
}
121+
// eslint-disable-next-line unicorn/consistent-function-scoping
122+
const getSequence = (start: number, end: number) => {
123+
if (!featureSequence || start < doc.min || end > doc.max) {
114124
return this.getSequence({ start, end, featureDoc: doc })
115-
},
116-
)
125+
}
126+
return Promise.resolve(
127+
featureSequence.slice(start - doc.min, end - doc.min),
128+
)
129+
}
130+
const result = await c.checkFeature(flatDoc, getSequence)
117131
if (result.length > 0) {
118132
await this.checkResultModel.insertMany(result)
119133
}

0 commit comments

Comments
 (0)