@vue-skuilder/db 0.2.37 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{contentSource-D_E7JaxR.d.ts → contentSource-2zVmcjKA.d.ts} +6 -1
- package/dist/core/index.cjs +155 -100
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.d.ts +5 -5
- package/dist/core/navigators/Pipeline.mjs +8 -0
- package/dist/core/navigators/Pipeline.mjs.map +1 -1
- package/dist/core/versionStamps.mjs +1 -1
- package/dist/{dataLayerProvider-BDshhSp_.d.ts → dataLayerProvider-rGyLQ93v.d.ts} +1 -1
- package/dist/diagnostics/index.d.ts +3 -3
- package/dist/impl/common/BaseUserDB.mjs +61 -34
- package/dist/impl/common/BaseUserDB.mjs.map +1 -1
- package/dist/impl/couch/CourseSyncService.mjs +23 -1
- package/dist/impl/couch/CourseSyncService.mjs.map +1 -1
- package/dist/impl/couch/courseDB.mjs +4 -0
- package/dist/impl/couch/courseDB.mjs.map +1 -1
- package/dist/impl/couch/index.cjs +177 -101
- package/dist/impl/couch/index.cjs.map +1 -1
- package/dist/impl/couch/index.d.ts +5 -3
- package/dist/impl/couch/updateQueue.mjs +69 -46
- package/dist/impl/couch/updateQueue.mjs.map +1 -1
- package/dist/impl/static/index.cjs +151 -100
- package/dist/impl/static/index.cjs.map +1 -1
- package/dist/impl/static/index.d.ts +4 -4
- package/dist/{index-BLDpFYG3.d.ts → index-C745YB_6.d.ts} +1 -1
- package/dist/index.cjs +187 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +23 -10
- package/dist/index.mjs +2 -1
- package/dist/study/SessionController.mjs +4 -0
- package/dist/study/SessionController.mjs.map +1 -1
- package/dist/{types-DChCz22D.d.ts → types-DF0JuPbs.d.ts} +1 -1
- package/dist/{types-legacy-fT5Y1Wuy.d.ts → types-legacy-DdVjg81H.d.ts} +1 -1
- package/dist/util/packer/index.d.ts +3 -3
- package/dist/util/perfMarks.mjs +30 -0
- package/dist/util/perfMarks.mjs.map +1 -0
- package/docs/session-lifecycle-and-replan.md +71 -58
- package/package.json +3 -3
- package/src/core/interfaces/courseDB.ts +6 -0
- package/src/core/navigators/Pipeline.ts +8 -0
- package/src/impl/common/BaseUserDB.ts +74 -46
- package/src/impl/couch/CourseSyncService.ts +19 -2
- package/src/impl/couch/courseDB.ts +5 -0
- package/src/impl/couch/updateQueue.ts +86 -82
- package/src/study/SessionController.ts +4 -0
- package/src/util/index.ts +1 -0
- package/src/util/perfMarks.ts +35 -0
- package/tests/impl/updateQueue.test.ts +57 -0
|
@@ -1472,8 +1472,10 @@ var init_updateQueue = __esm({
|
|
|
1472
1472
|
init_logger();
|
|
1473
1473
|
UpdateQueue = class extends Loggable {
|
|
1474
1474
|
_className = "UpdateQueue";
|
|
1475
|
-
|
|
1476
|
-
|
|
1475
|
+
/** Updates not yet taken by a write, per doc. */
|
|
1476
|
+
pending = /* @__PURE__ */ new Map();
|
|
1477
|
+
/** Docs with a drain loop running. */
|
|
1478
|
+
draining = /* @__PURE__ */ new Set();
|
|
1477
1479
|
readDB;
|
|
1478
1480
|
// Database for read operations
|
|
1479
1481
|
writeDB;
|
|
@@ -1491,6 +1493,9 @@ var init_updateQueue = __esm({
|
|
|
1491
1493
|
* **Error Handling Pattern:**
|
|
1492
1494
|
* - This method does NOT create documents if they don't exist
|
|
1493
1495
|
* - Callers are responsible for handling 404 errors and creating documents
|
|
1496
|
+
* - A rejected update is dropped from the queue: a caller that creates the
|
|
1497
|
+
* doc after a 404 has already applied its change and must not see it
|
|
1498
|
+
* re-applied by a later update to the same doc
|
|
1494
1499
|
* - This design maintains separation of concerns (UpdateQueue handles conflicts, callers handle lifecycle)
|
|
1495
1500
|
*
|
|
1496
1501
|
* @example
|
|
@@ -1507,12 +1512,16 @@ var init_updateQueue = __esm({
|
|
|
1507
1512
|
*/
|
|
1508
1513
|
update(id, update) {
|
|
1509
1514
|
logger.debug(`Update requested on doc: ${id}`);
|
|
1510
|
-
|
|
1511
|
-
this.
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1515
|
+
return new Promise((resolve, reject) => {
|
|
1516
|
+
const queue = this.pending.get(id) ?? [];
|
|
1517
|
+
queue.push({
|
|
1518
|
+
update,
|
|
1519
|
+
resolve,
|
|
1520
|
+
reject
|
|
1521
|
+
});
|
|
1522
|
+
this.pending.set(id, queue);
|
|
1523
|
+
if (!this.draining.has(id)) void this.drain(id);
|
|
1524
|
+
});
|
|
1516
1525
|
}
|
|
1517
1526
|
constructor(readDB, writeDB) {
|
|
1518
1527
|
super();
|
|
@@ -1523,64 +1532,56 @@ var init_updateQueue = __esm({
|
|
|
1523
1532
|
logger.debug(`db info: ${JSON.stringify(i)}`);
|
|
1524
1533
|
});
|
|
1525
1534
|
}
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1535
|
+
/** Writes the doc's queued updates, batch by batch, until none are left. */
|
|
1536
|
+
async drain(id) {
|
|
1537
|
+
this.draining.add(id);
|
|
1538
|
+
try {
|
|
1539
|
+
let batch;
|
|
1540
|
+
while ((batch = this.pending.get(id)) && batch.length > 0) {
|
|
1541
|
+
this.pending.delete(id);
|
|
1542
|
+
try {
|
|
1543
|
+
const doc = await this.write(
|
|
1544
|
+
id,
|
|
1545
|
+
batch.map((p) => p.update)
|
|
1546
|
+
);
|
|
1547
|
+
batch.forEach((p) => p.resolve(doc));
|
|
1548
|
+
} catch (e) {
|
|
1549
|
+
batch.forEach((p) => p.reject(e));
|
|
1550
|
+
}
|
|
1531
1551
|
}
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
} catch (e) {
|
|
1562
|
-
if (e.name === "conflict" && i < MAX_RETRIES - 1) {
|
|
1563
|
-
logger.warn(`Conflict on update for doc ${id}, retry #${i + 1}`);
|
|
1564
|
-
await new Promise((res) => setTimeout(res, 50 * Math.random()));
|
|
1565
|
-
} else if (e.name === "not_found" && i === 0) {
|
|
1566
|
-
logger.warn(`Update failed for ${id} - does not exist. Throwing to caller.`);
|
|
1567
|
-
delete this.inprogressUpdates[id];
|
|
1568
|
-
throw e;
|
|
1569
|
-
} else {
|
|
1570
|
-
delete this.inprogressUpdates[id];
|
|
1571
|
-
if (this.pendingUpdates[id]) {
|
|
1572
|
-
delete this.pendingUpdates[id];
|
|
1573
|
-
}
|
|
1574
|
-
logger.error(`Error on attemped update (retry ${i}): ${JSON.stringify(e)}`);
|
|
1575
|
-
throw e;
|
|
1576
|
-
}
|
|
1577
|
-
}
|
|
1552
|
+
} finally {
|
|
1553
|
+
this.draining.delete(id);
|
|
1554
|
+
}
|
|
1555
|
+
}
|
|
1556
|
+
/** One read-apply-put of `updates`, retried on conflict against a fresh read. */
|
|
1557
|
+
async write(id, updates) {
|
|
1558
|
+
logger.debug(`Applying ${updates.length} update(s) on doc: ${id}`);
|
|
1559
|
+
const MAX_RETRIES = 5;
|
|
1560
|
+
for (let i = 0; i < MAX_RETRIES; i++) {
|
|
1561
|
+
try {
|
|
1562
|
+
const doc = await this.readDB.get(id);
|
|
1563
|
+
let updatedDoc = {
|
|
1564
|
+
...doc
|
|
1565
|
+
};
|
|
1566
|
+
for (const update of updates) {
|
|
1567
|
+
updatedDoc = typeof update === "function" ? { ...updatedDoc, ...update(updatedDoc) } : { ...updatedDoc, ...update };
|
|
1568
|
+
}
|
|
1569
|
+
const res = await this.writeDB.put(updatedDoc);
|
|
1570
|
+
return { ...updatedDoc, _rev: res.rev };
|
|
1571
|
+
} catch (e) {
|
|
1572
|
+
if (e.name === "conflict" && i < MAX_RETRIES - 1) {
|
|
1573
|
+
logger.warn(`Conflict on update for doc ${id}, retry #${i + 1}`);
|
|
1574
|
+
await new Promise((res) => setTimeout(res, 50 * Math.random()));
|
|
1575
|
+
} else if (e.name === "not_found" && i === 0) {
|
|
1576
|
+
logger.warn(`Update failed for ${id} - does not exist. Throwing to caller.`);
|
|
1577
|
+
throw e;
|
|
1578
|
+
} else {
|
|
1579
|
+
logger.error(`Error on attemped update (retry ${i}): ${JSON.stringify(e)}`);
|
|
1580
|
+
throw e;
|
|
1578
1581
|
}
|
|
1579
|
-
throw new Error(`UpdateQueue failed for doc ${id} after ${MAX_RETRIES} retries.`);
|
|
1580
|
-
} else {
|
|
1581
|
-
throw new Error(`Empty Updates Queue Triggered`);
|
|
1582
1582
|
}
|
|
1583
1583
|
}
|
|
1584
|
+
throw new Error(`UpdateQueue failed for doc ${id} after ${MAX_RETRIES} retries.`);
|
|
1584
1585
|
}
|
|
1585
1586
|
};
|
|
1586
1587
|
}
|
|
@@ -1885,6 +1886,29 @@ var init_dataDirectory = __esm({
|
|
|
1885
1886
|
}
|
|
1886
1887
|
});
|
|
1887
1888
|
|
|
1889
|
+
// src/util/perfMarks.ts
|
|
1890
|
+
function perfMark(name, detail) {
|
|
1891
|
+
try {
|
|
1892
|
+
globalThis.performance?.mark(name, detail ? { detail } : void 0);
|
|
1893
|
+
} catch {
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
function perfMeasure(name, start, end, detail) {
|
|
1897
|
+
try {
|
|
1898
|
+
globalThis.performance?.measure(name, {
|
|
1899
|
+
start,
|
|
1900
|
+
...end !== void 0 ? { end } : {},
|
|
1901
|
+
...detail ? { detail } : {}
|
|
1902
|
+
});
|
|
1903
|
+
} catch {
|
|
1904
|
+
}
|
|
1905
|
+
}
|
|
1906
|
+
var init_perfMarks = __esm({
|
|
1907
|
+
"src/util/perfMarks.ts"() {
|
|
1908
|
+
"use strict";
|
|
1909
|
+
}
|
|
1910
|
+
});
|
|
1911
|
+
|
|
1888
1912
|
// src/core/navigators/regulators.ts
|
|
1889
1913
|
function clamp01(x) {
|
|
1890
1914
|
return Math.min(1, Math.max(0, x));
|
|
@@ -2099,6 +2123,7 @@ var init_Pipeline = __esm({
|
|
|
2099
2123
|
import_common3 = require("@vue-skuilder/common");
|
|
2100
2124
|
init_navigators();
|
|
2101
2125
|
init_logger();
|
|
2126
|
+
init_perfMarks();
|
|
2102
2127
|
init_orchestration();
|
|
2103
2128
|
init_PipelineDebugger();
|
|
2104
2129
|
init_diversityRerank();
|
|
@@ -2302,6 +2327,13 @@ var init_Pipeline = __esm({
|
|
|
2302
2327
|
logger.info(
|
|
2303
2328
|
`[Pipeline:timing] total=${(tFilter - t0).toFixed(0)}ms (context=${(tContext - t0).toFixed(0)} generate=${(tGenerate - tContext).toFixed(0)} hydrate=${(tHydrate - tGenerate).toFixed(0)} filter=${(tFilter - tHydrate).toFixed(0)})`
|
|
2304
2329
|
);
|
|
2330
|
+
perfMeasure("sk:pipeline-run", t0, tFilter, {
|
|
2331
|
+
context: Math.round(tContext - t0),
|
|
2332
|
+
generate: Math.round(tGenerate - tContext),
|
|
2333
|
+
hydrate: Math.round(tHydrate - tGenerate),
|
|
2334
|
+
filter: Math.round(tFilter - tHydrate),
|
|
2335
|
+
binding: this.course?.readsLocal === void 0 ? "unknown" : this.course.readsLocal ? "local" : "remote"
|
|
2336
|
+
});
|
|
2305
2337
|
const topScores = result.slice(0, 3).map((c) => c.score);
|
|
2306
2338
|
logExecutionSummary(
|
|
2307
2339
|
this.generator.name,
|
|
@@ -4258,6 +4290,9 @@ var init_BaseUserDB = __esm({
|
|
|
4258
4290
|
// Database to use for write operations (local-first approach)
|
|
4259
4291
|
updateQueue;
|
|
4260
4292
|
_hydration = { state: "not-required" };
|
|
4293
|
+
/** See scanScheduledCards. Bumped by every write to scheduled reviews. */
|
|
4294
|
+
_scheduledScan = null;
|
|
4295
|
+
_scheduledGeneration = 0;
|
|
4261
4296
|
/** In-flight hydration, so concurrent callers can wait for a real answer. */
|
|
4262
4297
|
_hydrationPromise = null;
|
|
4263
4298
|
/**
|
|
@@ -4502,18 +4537,38 @@ Currently logged-in as ${this._username}.`
|
|
|
4502
4537
|
*
|
|
4503
4538
|
*/
|
|
4504
4539
|
async getActiveCards() {
|
|
4540
|
+
return (await this.scanScheduledCards()).map((doc) => ({
|
|
4541
|
+
courseID: doc.courseId,
|
|
4542
|
+
cardID: doc.cardId
|
|
4543
|
+
}));
|
|
4544
|
+
}
|
|
4545
|
+
/**
|
|
4546
|
+
* The user's scheduled reviews (`card_review_*`), all of them: one `allDocs`
|
|
4547
|
+
* scan shared by concurrent readers. A pipeline run's generators start
|
|
4548
|
+
* together (`CompositeGenerator`), and each used to scan the range itself
|
|
4549
|
+
* (`getActiveCards` from ELO and Prescribed, `getReviewstoDate` from SRS).
|
|
4550
|
+
* Sharing only an in-flight scan keeps reads as fresh as before; a schedule
|
|
4551
|
+
* or removal of a review starts a new scan for anyone reading after it.
|
|
4552
|
+
* Docs are shared between callers: copy before mutating.
|
|
4553
|
+
*/
|
|
4554
|
+
scanScheduledCards() {
|
|
4555
|
+
const inFlight = this._scheduledScan;
|
|
4556
|
+
if (inFlight && inFlight.generation === this._scheduledGeneration) return inFlight.scan;
|
|
4505
4557
|
const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
|
|
4506
|
-
const
|
|
4507
|
-
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4558
|
+
const entry = {
|
|
4559
|
+
generation: this._scheduledGeneration,
|
|
4560
|
+
scan: this.remoteDB.allDocs({
|
|
4561
|
+
startkey: keys.startkey,
|
|
4562
|
+
endkey: keys.endkey,
|
|
4563
|
+
include_docs: true
|
|
4564
|
+
}).then((res) => res.rows.map((row) => row.doc))
|
|
4565
|
+
};
|
|
4566
|
+
this._scheduledScan = entry;
|
|
4567
|
+
const done = () => {
|
|
4568
|
+
if (this._scheduledScan === entry) this._scheduledScan = null;
|
|
4569
|
+
};
|
|
4570
|
+
entry.scan.then(done, done);
|
|
4571
|
+
return entry.scan;
|
|
4517
4572
|
}
|
|
4518
4573
|
async getActivityRecords() {
|
|
4519
4574
|
try {
|
|
@@ -4579,28 +4634,23 @@ Currently logged-in as ${this._username}.`
|
|
|
4579
4634
|
}
|
|
4580
4635
|
}
|
|
4581
4636
|
async getReviewstoDate(targetDate, course_id) {
|
|
4582
|
-
const
|
|
4583
|
-
const reviews = await this.remoteDB.allDocs({
|
|
4584
|
-
startkey: keys.startkey,
|
|
4585
|
-
endkey: keys.endkey,
|
|
4586
|
-
include_docs: true
|
|
4587
|
-
});
|
|
4637
|
+
const reviews = await this.scanScheduledCards();
|
|
4588
4638
|
log3(
|
|
4589
4639
|
`Fetching ${this._username}'s scheduled reviews${course_id ? ` for course ${course_id}` : ""}.`
|
|
4590
4640
|
);
|
|
4591
|
-
return reviews.
|
|
4592
|
-
if (
|
|
4641
|
+
return reviews.filter((doc) => {
|
|
4642
|
+
if (doc._id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
4593
4643
|
const date = import_moment5.default.utc(
|
|
4594
|
-
|
|
4644
|
+
doc._id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
4595
4645
|
REVIEW_TIME_FORMAT
|
|
4596
4646
|
);
|
|
4597
4647
|
if (targetDate.isAfter(date)) {
|
|
4598
|
-
if (course_id === void 0 ||
|
|
4648
|
+
if (course_id === void 0 || doc.courseId === course_id) {
|
|
4599
4649
|
return true;
|
|
4600
4650
|
}
|
|
4601
4651
|
}
|
|
4602
4652
|
}
|
|
4603
|
-
}).map((
|
|
4653
|
+
}).map((doc) => ({ ...doc }));
|
|
4604
4654
|
}
|
|
4605
4655
|
async getReviewsForcast(daysCount, course_id) {
|
|
4606
4656
|
const time = import_moment5.default.utc().add(daysCount, "days");
|
|
@@ -4984,22 +5034,20 @@ Currently logged-in as ${this._username}.`
|
|
|
4984
5034
|
async putCardRecord(record) {
|
|
4985
5035
|
const cardHistoryID = getCardHistoryID(record.courseID, record.cardID);
|
|
4986
5036
|
record.timeStamp = import_moment5.default.utc(record.timeStamp).toString();
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4994
|
-
|
|
4995
|
-
|
|
4996
|
-
|
|
4997
|
-
|
|
4998
|
-
|
|
4999
|
-
|
|
5000
|
-
|
|
5001
|
-
}
|
|
5002
|
-
);
|
|
5037
|
+
const append = (h) => {
|
|
5038
|
+
h.records.push(record);
|
|
5039
|
+
h.bestInterval = h.bestInterval || 0;
|
|
5040
|
+
if (areQuestionRecords(h)) {
|
|
5041
|
+
h.lapses = getLapses(h.records);
|
|
5042
|
+
h.streak = getStreak(h.records);
|
|
5043
|
+
} else {
|
|
5044
|
+
h.lapses = h.lapses || 0;
|
|
5045
|
+
h.streak = h.streak || 0;
|
|
5046
|
+
}
|
|
5047
|
+
return h;
|
|
5048
|
+
};
|
|
5049
|
+
const appendToExisting = async () => {
|
|
5050
|
+
const cardHistory = await this.update(cardHistoryID, append);
|
|
5003
5051
|
cardHistory.records = cardHistory.records.map((record2) => {
|
|
5004
5052
|
const ret = {
|
|
5005
5053
|
...record2
|
|
@@ -5008,6 +5056,9 @@ Currently logged-in as ${this._username}.`
|
|
|
5008
5056
|
return ret;
|
|
5009
5057
|
});
|
|
5010
5058
|
return cardHistory;
|
|
5059
|
+
};
|
|
5060
|
+
try {
|
|
5061
|
+
return await appendToExisting();
|
|
5011
5062
|
} catch (e) {
|
|
5012
5063
|
const reason = e;
|
|
5013
5064
|
if (reason.status === 404) {
|
|
@@ -5024,6 +5075,9 @@ Currently logged-in as ${this._username}.`
|
|
|
5024
5075
|
const putResult = await this.writeDB.put(initCardHistory);
|
|
5025
5076
|
return { ...initCardHistory, _rev: putResult.rev };
|
|
5026
5077
|
} catch (creationError) {
|
|
5078
|
+
if (creationError.name === "conflict") {
|
|
5079
|
+
return appendToExisting();
|
|
5080
|
+
}
|
|
5027
5081
|
throw new Error(
|
|
5028
5082
|
`Failed to create CardHistory for ${cardHistoryID}. Reason: ${creationError}`
|
|
5029
5083
|
);
|
|
@@ -5067,6 +5121,7 @@ Currently logged-in as ${this._username}.`
|
|
|
5067
5121
|
const deletePromises = duplicateDocIds.map(async (docId) => {
|
|
5068
5122
|
try {
|
|
5069
5123
|
const doc = await this.remoteDB.get(docId);
|
|
5124
|
+
this._scheduledGeneration++;
|
|
5070
5125
|
await this.writeDB.remove(doc);
|
|
5071
5126
|
log3(`Successfully removed duplicate review: ${docId}`);
|
|
5072
5127
|
} catch (error) {
|
|
@@ -5212,9 +5267,11 @@ Currently logged-in as ${this._username}.`
|
|
|
5212
5267
|
}
|
|
5213
5268
|
}
|
|
5214
5269
|
async scheduleCardReview(review) {
|
|
5270
|
+
this._scheduledGeneration++;
|
|
5215
5271
|
return scheduleCardReviewLocal(this.writeDB, review);
|
|
5216
5272
|
}
|
|
5217
5273
|
async removeScheduledCardReview(reviewId) {
|
|
5274
|
+
this._scheduledGeneration++;
|
|
5218
5275
|
return removeScheduledCardReviewLocal(this.writeDB, reviewId);
|
|
5219
5276
|
}
|
|
5220
5277
|
async registerForClassroom(_classId, _registerAs) {
|
|
@@ -6836,6 +6893,10 @@ var init_courseDB2 = __esm({
|
|
|
6836
6893
|
* values may be stale, so read-modify-write cycles must go through
|
|
6837
6894
|
* the remote DB to avoid conflicts).
|
|
6838
6895
|
*/
|
|
6896
|
+
/** Reads go to this device's replica (perf marks report it as the session's binding). */
|
|
6897
|
+
get readsLocal() {
|
|
6898
|
+
return this.db !== this.remoteDB;
|
|
6899
|
+
}
|
|
6839
6900
|
constructor(id, userLookup, localDB) {
|
|
6840
6901
|
this.id = id;
|
|
6841
6902
|
const remote = getCourseDB(this.id);
|
|
@@ -7862,6 +7923,7 @@ var init_CourseSyncService = __esm({
|
|
|
7862
7923
|
init_pouchdb_setup();
|
|
7863
7924
|
init_couch();
|
|
7864
7925
|
init_logger();
|
|
7926
|
+
init_perfMarks();
|
|
7865
7927
|
SYNC_MARKER_ID = "_local/sk-course-sync-complete";
|
|
7866
7928
|
DEFAULT_REPLICATION = {
|
|
7867
7929
|
batchSize: 1e3,
|
|
@@ -7960,6 +8022,7 @@ var init_CourseSyncService = __esm({
|
|
|
7960
8022
|
entry.localDB = localDB;
|
|
7961
8023
|
entry.status = { state: "ready" };
|
|
7962
8024
|
entry.readyPromise = null;
|
|
8025
|
+
perfMark("sk:course-sync-ready", { courseId, from: "marker" });
|
|
7963
8026
|
logger.info(
|
|
7964
8027
|
`[CourseSyncService] Using this device's replica of course ${courseId}; refreshing in the background`
|
|
7965
8028
|
);
|
|
@@ -8002,6 +8065,12 @@ var init_CourseSyncService = __esm({
|
|
|
8002
8065
|
syncTimeMs,
|
|
8003
8066
|
viewWarmTimeMs
|
|
8004
8067
|
};
|
|
8068
|
+
perfMark("sk:course-sync-refreshed", {
|
|
8069
|
+
courseId,
|
|
8070
|
+
docs: result.docs_written,
|
|
8071
|
+
syncTimeMs,
|
|
8072
|
+
viewWarmTimeMs
|
|
8073
|
+
});
|
|
8005
8074
|
logger.info(
|
|
8006
8075
|
`[CourseSyncService] Background refresh of course ${courseId}: ${result.docs_written} docs in ${syncTimeMs}ms, views ${viewWarmTimeMs}ms`
|
|
8007
8076
|
);
|
|
@@ -8102,6 +8171,11 @@ var init_CourseSyncService = __esm({
|
|
|
8102
8171
|
);
|
|
8103
8172
|
const result = await this.replicate(remoteDB, localDB);
|
|
8104
8173
|
const syncTimeMs = Date.now() - syncStart;
|
|
8174
|
+
perfMark("sk:course-sync-replicated", {
|
|
8175
|
+
courseId,
|
|
8176
|
+
docs: result.docs_written,
|
|
8177
|
+
ms: syncTimeMs
|
|
8178
|
+
});
|
|
8105
8179
|
logger.info(
|
|
8106
8180
|
`[CourseSyncService] Replication complete for course ${courseId}: ${result.docs_written} docs in ${syncTimeMs}ms`
|
|
8107
8181
|
);
|
|
@@ -8119,6 +8193,7 @@ var init_CourseSyncService = __esm({
|
|
|
8119
8193
|
syncTimeMs,
|
|
8120
8194
|
viewWarmTimeMs
|
|
8121
8195
|
};
|
|
8196
|
+
perfMark("sk:course-sync-ready", { courseId, from: "sync", viewWarmTimeMs });
|
|
8122
8197
|
} catch (e) {
|
|
8123
8198
|
const errorMsg = e instanceof Error ? e.message : String(e);
|
|
8124
8199
|
logger.error(
|
|
@@ -8206,7 +8281,8 @@ var init_CourseSyncService = __esm({
|
|
|
8206
8281
|
try {
|
|
8207
8282
|
localEpoch = await localDB.get("db-epoch");
|
|
8208
8283
|
} catch {
|
|
8209
|
-
|
|
8284
|
+
const info = await localDB.info();
|
|
8285
|
+
return info.doc_count > 0 || !!info.update_seq;
|
|
8210
8286
|
}
|
|
8211
8287
|
return remoteEpoch.epoch !== localEpoch.epoch;
|
|
8212
8288
|
} catch {
|