@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.
@@ -4290,6 +4290,9 @@ var init_BaseUserDB = __esm({
4290
4290
  // Database to use for write operations (local-first approach)
4291
4291
  updateQueue;
4292
4292
  _hydration = { state: "not-required" };
4293
+ /** See scanScheduledCards. Bumped by every write to scheduled reviews. */
4294
+ _scheduledScan = null;
4295
+ _scheduledGeneration = 0;
4293
4296
  /** In-flight hydration, so concurrent callers can wait for a real answer. */
4294
4297
  _hydrationPromise = null;
4295
4298
  /**
@@ -4534,18 +4537,38 @@ Currently logged-in as ${this._username}.`
4534
4537
  *
4535
4538
  */
4536
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;
4537
4557
  const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
4538
- const reviews = await this.remoteDB.allDocs({
4539
- startkey: keys.startkey,
4540
- endkey: keys.endkey,
4541
- include_docs: true
4542
- });
4543
- return reviews.rows.map((r) => {
4544
- return {
4545
- courseID: r.doc.courseId,
4546
- cardID: r.doc.cardId
4547
- };
4548
- });
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;
4549
4572
  }
4550
4573
  async getActivityRecords() {
4551
4574
  try {
@@ -4611,28 +4634,23 @@ Currently logged-in as ${this._username}.`
4611
4634
  }
4612
4635
  }
4613
4636
  async getReviewstoDate(targetDate, course_id) {
4614
- const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
4615
- const reviews = await this.remoteDB.allDocs({
4616
- startkey: keys.startkey,
4617
- endkey: keys.endkey,
4618
- include_docs: true
4619
- });
4637
+ const reviews = await this.scanScheduledCards();
4620
4638
  log3(
4621
4639
  `Fetching ${this._username}'s scheduled reviews${course_id ? ` for course ${course_id}` : ""}.`
4622
4640
  );
4623
- return reviews.rows.filter((r) => {
4624
- if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
4641
+ return reviews.filter((doc) => {
4642
+ if (doc._id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
4625
4643
  const date = import_moment5.default.utc(
4626
- r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
4644
+ doc._id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
4627
4645
  REVIEW_TIME_FORMAT
4628
4646
  );
4629
4647
  if (targetDate.isAfter(date)) {
4630
- if (course_id === void 0 || r.doc.courseId === course_id) {
4648
+ if (course_id === void 0 || doc.courseId === course_id) {
4631
4649
  return true;
4632
4650
  }
4633
4651
  }
4634
4652
  }
4635
- }).map((r) => r.doc);
4653
+ }).map((doc) => ({ ...doc }));
4636
4654
  }
4637
4655
  async getReviewsForcast(daysCount, course_id) {
4638
4656
  const time = import_moment5.default.utc().add(daysCount, "days");
@@ -5103,6 +5121,7 @@ Currently logged-in as ${this._username}.`
5103
5121
  const deletePromises = duplicateDocIds.map(async (docId) => {
5104
5122
  try {
5105
5123
  const doc = await this.remoteDB.get(docId);
5124
+ this._scheduledGeneration++;
5106
5125
  await this.writeDB.remove(doc);
5107
5126
  log3(`Successfully removed duplicate review: ${docId}`);
5108
5127
  } catch (error) {
@@ -5248,9 +5267,11 @@ Currently logged-in as ${this._username}.`
5248
5267
  }
5249
5268
  }
5250
5269
  async scheduleCardReview(review) {
5270
+ this._scheduledGeneration++;
5251
5271
  return scheduleCardReviewLocal(this.writeDB, review);
5252
5272
  }
5253
5273
  async removeScheduledCardReview(reviewId) {
5274
+ this._scheduledGeneration++;
5254
5275
  return removeScheduledCardReviewLocal(this.writeDB, reviewId);
5255
5276
  }
5256
5277
  async registerForClassroom(_classId, _registerAs) {