-
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
19b9283
commit 6d85476
Showing
9 changed files
with
300 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const kInsertions = Symbol("lyra.insertions"); | ||
|
||
const warn = | ||
"process" in globalThis | ||
? process.emitWarning | ||
: function emitWarning(message: string, options: { code: string }) { | ||
console.warn(`[WARNING] [${options.code}] ${message}`); | ||
}; | ||
|
||
export function trackInsertion(_lyra: unknown) { | ||
const lyra = _lyra as object & { [kInsertions]?: number }; | ||
|
||
if (typeof lyra[kInsertions] !== "number") { | ||
queueMicrotask(() => { | ||
lyra[kInsertions] = undefined; | ||
}); | ||
|
||
lyra[kInsertions] = 0; | ||
} | ||
|
||
if (lyra[kInsertions]! > 1000) { | ||
warn( | ||
"Lyra's insert operation is synchronous. Please avoid inserting a large number of document in a single operation in order not to block the main thread.", | ||
{ code: "LYRA0001" }, | ||
); | ||
|
||
lyra[kInsertions] = -1; | ||
} else if (lyra[kInsertions] >= 0) { | ||
lyra[kInsertions]++; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.