@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.
@@ -4933,6 +4933,9 @@ var init_BaseUserDB = __esm({
4933
4933
  // Database to use for write operations (local-first approach)
4934
4934
  updateQueue;
4935
4935
  _hydration = { state: "not-required" };
4936
+ /** See scanScheduledCards. Bumped by every write to scheduled reviews. */
4937
+ _scheduledScan = null;
4938
+ _scheduledGeneration = 0;
4936
4939
  /** In-flight hydration, so concurrent callers can wait for a real answer. */
4937
4940
  _hydrationPromise = null;
4938
4941
  /**
@@ -5177,18 +5180,38 @@ Currently logged-in as ${this._username}.`
5177
5180
  *
5178
5181
  */
5179
5182
  async getActiveCards() {
5183
+ return (await this.scanScheduledCards()).map((doc) => ({
5184
+ courseID: doc.courseId,
5185
+ cardID: doc.cardId
5186
+ }));
5187
+ }
5188
+ /**
5189
+ * The user's scheduled reviews (`card_review_*`), all of them: one `allDocs`
5190
+ * scan shared by concurrent readers. A pipeline run's generators start
5191
+ * together (`CompositeGenerator`), and each used to scan the range itself
5192
+ * (`getActiveCards` from ELO and Prescribed, `getReviewstoDate` from SRS).
5193
+ * Sharing only an in-flight scan keeps reads as fresh as before; a schedule
5194
+ * or removal of a review starts a new scan for anyone reading after it.
5195
+ * Docs are shared between callers: copy before mutating.
5196
+ */
5197
+ scanScheduledCards() {
5198
+ const inFlight = this._scheduledScan;
5199
+ if (inFlight && inFlight.generation === this._scheduledGeneration) return inFlight.scan;
5180
5200
  const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
5181
- const reviews = await this.remoteDB.allDocs({
5182
- startkey: keys.startkey,
5183
- endkey: keys.endkey,
5184
- include_docs: true
5185
- });
5186
- return reviews.rows.map((r) => {
5187
- return {
5188
- courseID: r.doc.courseId,
5189
- cardID: r.doc.cardId
5190
- };
5191
- });
5201
+ const entry = {
5202
+ generation: this._scheduledGeneration,
5203
+ scan: this.remoteDB.allDocs({
5204
+ startkey: keys.startkey,
5205
+ endkey: keys.endkey,
5206
+ include_docs: true
5207
+ }).then((res) => res.rows.map((row) => row.doc))
5208
+ };
5209
+ this._scheduledScan = entry;
5210
+ const done = () => {
5211
+ if (this._scheduledScan === entry) this._scheduledScan = null;
5212
+ };
5213
+ entry.scan.then(done, done);
5214
+ return entry.scan;
5192
5215
  }
5193
5216
  async getActivityRecords() {
5194
5217
  try {
@@ -5254,28 +5277,23 @@ Currently logged-in as ${this._username}.`
5254
5277
  }
5255
5278
  }
5256
5279
  async getReviewstoDate(targetDate, course_id) {
5257
- const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
5258
- const reviews = await this.remoteDB.allDocs({
5259
- startkey: keys.startkey,
5260
- endkey: keys.endkey,
5261
- include_docs: true
5262
- });
5280
+ const reviews = await this.scanScheduledCards();
5263
5281
  log2(
5264
5282
  `Fetching ${this._username}'s scheduled reviews${course_id ? ` for course ${course_id}` : ""}.`
5265
5283
  );
5266
- return reviews.rows.filter((r) => {
5267
- if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
5284
+ return reviews.filter((doc) => {
5285
+ if (doc._id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
5268
5286
  const date = import_moment6.default.utc(
5269
- r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
5287
+ doc._id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
5270
5288
  REVIEW_TIME_FORMAT
5271
5289
  );
5272
5290
  if (targetDate.isAfter(date)) {
5273
- if (course_id === void 0 || r.doc.courseId === course_id) {
5291
+ if (course_id === void 0 || doc.courseId === course_id) {
5274
5292
  return true;
5275
5293
  }
5276
5294
  }
5277
5295
  }
5278
- }).map((r) => r.doc);
5296
+ }).map((doc) => ({ ...doc }));
5279
5297
  }
5280
5298
  async getReviewsForcast(daysCount, course_id) {
5281
5299
  const time = import_moment6.default.utc().add(daysCount, "days");
@@ -5746,6 +5764,7 @@ Currently logged-in as ${this._username}.`
5746
5764
  const deletePromises = duplicateDocIds.map(async (docId) => {
5747
5765
  try {
5748
5766
  const doc = await this.remoteDB.get(docId);
5767
+ this._scheduledGeneration++;
5749
5768
  await this.writeDB.remove(doc);
5750
5769
  log2(`Successfully removed duplicate review: ${docId}`);
5751
5770
  } catch (error) {
@@ -5891,9 +5910,11 @@ Currently logged-in as ${this._username}.`
5891
5910
  }
5892
5911
  }
5893
5912
  async scheduleCardReview(review) {
5913
+ this._scheduledGeneration++;
5894
5914
  return scheduleCardReviewLocal(this.writeDB, review);
5895
5915
  }
5896
5916
  async removeScheduledCardReview(reviewId) {
5917
+ this._scheduledGeneration++;
5897
5918
  return removeScheduledCardReviewLocal(this.writeDB, reviewId);
5898
5919
  }
5899
5920
  async registerForClassroom(_classId, _registerAs) {