@vue-skuilder/db 0.3.0 → 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/core/index.cjs +43 -22
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/versionStamps.mjs +1 -1
- package/dist/impl/common/BaseUserDB.mjs +43 -21
- package/dist/impl/common/BaseUserDB.mjs.map +1 -1
- package/dist/impl/couch/index.cjs +43 -22
- package/dist/impl/couch/index.cjs.map +1 -1
- package/dist/impl/static/index.cjs +43 -22
- package/dist/impl/static/index.cjs.map +1 -1
- package/dist/index.cjs +44 -23
- package/dist/index.cjs.map +1 -1
- package/docs/session-lifecycle-and-replan.md +71 -58
- package/package.json +3 -3
- package/src/impl/common/BaseUserDB.ts +47 -25
package/dist/core/index.cjs
CHANGED
|
@@ -7877,6 +7877,9 @@ var init_BaseUserDB = __esm({
|
|
|
7877
7877
|
// Database to use for write operations (local-first approach)
|
|
7878
7878
|
updateQueue;
|
|
7879
7879
|
_hydration = { state: "not-required" };
|
|
7880
|
+
/** See scanScheduledCards. Bumped by every write to scheduled reviews. */
|
|
7881
|
+
_scheduledScan = null;
|
|
7882
|
+
_scheduledGeneration = 0;
|
|
7880
7883
|
/** In-flight hydration, so concurrent callers can wait for a real answer. */
|
|
7881
7884
|
_hydrationPromise = null;
|
|
7882
7885
|
/**
|
|
@@ -8121,18 +8124,38 @@ Currently logged-in as ${this._username}.`
|
|
|
8121
8124
|
*
|
|
8122
8125
|
*/
|
|
8123
8126
|
async getActiveCards() {
|
|
8127
|
+
return (await this.scanScheduledCards()).map((doc) => ({
|
|
8128
|
+
courseID: doc.courseId,
|
|
8129
|
+
cardID: doc.cardId
|
|
8130
|
+
}));
|
|
8131
|
+
}
|
|
8132
|
+
/**
|
|
8133
|
+
* The user's scheduled reviews (`card_review_*`), all of them: one `allDocs`
|
|
8134
|
+
* scan shared by concurrent readers. A pipeline run's generators start
|
|
8135
|
+
* together (`CompositeGenerator`), and each used to scan the range itself
|
|
8136
|
+
* (`getActiveCards` from ELO and Prescribed, `getReviewstoDate` from SRS).
|
|
8137
|
+
* Sharing only an in-flight scan keeps reads as fresh as before; a schedule
|
|
8138
|
+
* or removal of a review starts a new scan for anyone reading after it.
|
|
8139
|
+
* Docs are shared between callers: copy before mutating.
|
|
8140
|
+
*/
|
|
8141
|
+
scanScheduledCards() {
|
|
8142
|
+
const inFlight = this._scheduledScan;
|
|
8143
|
+
if (inFlight && inFlight.generation === this._scheduledGeneration) return inFlight.scan;
|
|
8124
8144
|
const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
|
|
8125
|
-
const
|
|
8126
|
-
|
|
8127
|
-
|
|
8128
|
-
|
|
8129
|
-
|
|
8130
|
-
|
|
8131
|
-
|
|
8132
|
-
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8145
|
+
const entry = {
|
|
8146
|
+
generation: this._scheduledGeneration,
|
|
8147
|
+
scan: this.remoteDB.allDocs({
|
|
8148
|
+
startkey: keys.startkey,
|
|
8149
|
+
endkey: keys.endkey,
|
|
8150
|
+
include_docs: true
|
|
8151
|
+
}).then((res) => res.rows.map((row) => row.doc))
|
|
8152
|
+
};
|
|
8153
|
+
this._scheduledScan = entry;
|
|
8154
|
+
const done = () => {
|
|
8155
|
+
if (this._scheduledScan === entry) this._scheduledScan = null;
|
|
8156
|
+
};
|
|
8157
|
+
entry.scan.then(done, done);
|
|
8158
|
+
return entry.scan;
|
|
8136
8159
|
}
|
|
8137
8160
|
async getActivityRecords() {
|
|
8138
8161
|
try {
|
|
@@ -8198,28 +8221,23 @@ Currently logged-in as ${this._username}.`
|
|
|
8198
8221
|
}
|
|
8199
8222
|
}
|
|
8200
8223
|
async getReviewstoDate(targetDate, course_id) {
|
|
8201
|
-
const
|
|
8202
|
-
const reviews = await this.remoteDB.allDocs({
|
|
8203
|
-
startkey: keys.startkey,
|
|
8204
|
-
endkey: keys.endkey,
|
|
8205
|
-
include_docs: true
|
|
8206
|
-
});
|
|
8224
|
+
const reviews = await this.scanScheduledCards();
|
|
8207
8225
|
log3(
|
|
8208
8226
|
`Fetching ${this._username}'s scheduled reviews${course_id ? ` for course ${course_id}` : ""}.`
|
|
8209
8227
|
);
|
|
8210
|
-
return reviews.
|
|
8211
|
-
if (
|
|
8228
|
+
return reviews.filter((doc) => {
|
|
8229
|
+
if (doc._id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
|
|
8212
8230
|
const date = import_moment6.default.utc(
|
|
8213
|
-
|
|
8231
|
+
doc._id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
|
|
8214
8232
|
REVIEW_TIME_FORMAT
|
|
8215
8233
|
);
|
|
8216
8234
|
if (targetDate.isAfter(date)) {
|
|
8217
|
-
if (course_id === void 0 ||
|
|
8235
|
+
if (course_id === void 0 || doc.courseId === course_id) {
|
|
8218
8236
|
return true;
|
|
8219
8237
|
}
|
|
8220
8238
|
}
|
|
8221
8239
|
}
|
|
8222
|
-
}).map((
|
|
8240
|
+
}).map((doc) => ({ ...doc }));
|
|
8223
8241
|
}
|
|
8224
8242
|
async getReviewsForcast(daysCount, course_id) {
|
|
8225
8243
|
const time = import_moment6.default.utc().add(daysCount, "days");
|
|
@@ -8690,6 +8708,7 @@ Currently logged-in as ${this._username}.`
|
|
|
8690
8708
|
const deletePromises = duplicateDocIds.map(async (docId) => {
|
|
8691
8709
|
try {
|
|
8692
8710
|
const doc = await this.remoteDB.get(docId);
|
|
8711
|
+
this._scheduledGeneration++;
|
|
8693
8712
|
await this.writeDB.remove(doc);
|
|
8694
8713
|
log3(`Successfully removed duplicate review: ${docId}`);
|
|
8695
8714
|
} catch (error) {
|
|
@@ -8835,9 +8854,11 @@ Currently logged-in as ${this._username}.`
|
|
|
8835
8854
|
}
|
|
8836
8855
|
}
|
|
8837
8856
|
async scheduleCardReview(review) {
|
|
8857
|
+
this._scheduledGeneration++;
|
|
8838
8858
|
return scheduleCardReviewLocal(this.writeDB, review);
|
|
8839
8859
|
}
|
|
8840
8860
|
async removeScheduledCardReview(reviewId) {
|
|
8861
|
+
this._scheduledGeneration++;
|
|
8841
8862
|
return removeScheduledCardReviewLocal(this.writeDB, reviewId);
|
|
8842
8863
|
}
|
|
8843
8864
|
async registerForClassroom(_classId, _registerAs) {
|