@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/index.cjs CHANGED
@@ -3624,7 +3624,7 @@ var FRAMEWORK_VERSION, hostAppVersion, DEFAULT_STRATEGY_HASH;
3624
3624
  var init_versionStamps = __esm({
3625
3625
  "src/core/versionStamps.ts"() {
3626
3626
  "use strict";
3627
- FRAMEWORK_VERSION = true ? "0.3.0" : "dev";
3627
+ FRAMEWORK_VERSION = true ? "0.3.1" : "dev";
3628
3628
  DEFAULT_STRATEGY_HASH = "default";
3629
3629
  }
3630
3630
  });
@@ -10738,6 +10738,9 @@ var init_BaseUserDB = __esm({
10738
10738
  // Database to use for write operations (local-first approach)
10739
10739
  updateQueue;
10740
10740
  _hydration = { state: "not-required" };
10741
+ /** See scanScheduledCards. Bumped by every write to scheduled reviews. */
10742
+ _scheduledScan = null;
10743
+ _scheduledGeneration = 0;
10741
10744
  /** In-flight hydration, so concurrent callers can wait for a real answer. */
10742
10745
  _hydrationPromise = null;
10743
10746
  /**
@@ -10982,18 +10985,38 @@ Currently logged-in as ${this._username}.`
10982
10985
  *
10983
10986
  */
10984
10987
  async getActiveCards() {
10988
+ return (await this.scanScheduledCards()).map((doc) => ({
10989
+ courseID: doc.courseId,
10990
+ cardID: doc.cardId
10991
+ }));
10992
+ }
10993
+ /**
10994
+ * The user's scheduled reviews (`card_review_*`), all of them: one `allDocs`
10995
+ * scan shared by concurrent readers. A pipeline run's generators start
10996
+ * together (`CompositeGenerator`), and each used to scan the range itself
10997
+ * (`getActiveCards` from ELO and Prescribed, `getReviewstoDate` from SRS).
10998
+ * Sharing only an in-flight scan keeps reads as fresh as before; a schedule
10999
+ * or removal of a review starts a new scan for anyone reading after it.
11000
+ * Docs are shared between callers: copy before mutating.
11001
+ */
11002
+ scanScheduledCards() {
11003
+ const inFlight = this._scheduledScan;
11004
+ if (inFlight && inFlight.generation === this._scheduledGeneration) return inFlight.scan;
10985
11005
  const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
10986
- const reviews = await this.remoteDB.allDocs({
10987
- startkey: keys.startkey,
10988
- endkey: keys.endkey,
10989
- include_docs: true
10990
- });
10991
- return reviews.rows.map((r) => {
10992
- return {
10993
- courseID: r.doc.courseId,
10994
- cardID: r.doc.cardId
10995
- };
10996
- });
11006
+ const entry = {
11007
+ generation: this._scheduledGeneration,
11008
+ scan: this.remoteDB.allDocs({
11009
+ startkey: keys.startkey,
11010
+ endkey: keys.endkey,
11011
+ include_docs: true
11012
+ }).then((res) => res.rows.map((row) => row.doc))
11013
+ };
11014
+ this._scheduledScan = entry;
11015
+ const done = () => {
11016
+ if (this._scheduledScan === entry) this._scheduledScan = null;
11017
+ };
11018
+ entry.scan.then(done, done);
11019
+ return entry.scan;
10997
11020
  }
10998
11021
  async getActivityRecords() {
10999
11022
  try {
@@ -11059,28 +11082,23 @@ Currently logged-in as ${this._username}.`
11059
11082
  }
11060
11083
  }
11061
11084
  async getReviewstoDate(targetDate, course_id) {
11062
- const keys = getStartAndEndKeys(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */]);
11063
- const reviews = await this.remoteDB.allDocs({
11064
- startkey: keys.startkey,
11065
- endkey: keys.endkey,
11066
- include_docs: true
11067
- });
11085
+ const reviews = await this.scanScheduledCards();
11068
11086
  log3(
11069
11087
  `Fetching ${this._username}'s scheduled reviews${course_id ? ` for course ${course_id}` : ""}.`
11070
11088
  );
11071
- return reviews.rows.filter((r) => {
11072
- if (r.id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
11089
+ return reviews.filter((doc) => {
11090
+ if (doc._id.startsWith(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */])) {
11073
11091
  const date = import_moment7.default.utc(
11074
- r.id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
11092
+ doc._id.substr(DocTypePrefixes["SCHEDULED_CARD" /* SCHEDULED_CARD */].length),
11075
11093
  REVIEW_TIME_FORMAT
11076
11094
  );
11077
11095
  if (targetDate.isAfter(date)) {
11078
- if (course_id === void 0 || r.doc.courseId === course_id) {
11096
+ if (course_id === void 0 || doc.courseId === course_id) {
11079
11097
  return true;
11080
11098
  }
11081
11099
  }
11082
11100
  }
11083
- }).map((r) => r.doc);
11101
+ }).map((doc) => ({ ...doc }));
11084
11102
  }
11085
11103
  async getReviewsForcast(daysCount, course_id) {
11086
11104
  const time = import_moment7.default.utc().add(daysCount, "days");
@@ -11551,6 +11569,7 @@ Currently logged-in as ${this._username}.`
11551
11569
  const deletePromises = duplicateDocIds.map(async (docId) => {
11552
11570
  try {
11553
11571
  const doc = await this.remoteDB.get(docId);
11572
+ this._scheduledGeneration++;
11554
11573
  await this.writeDB.remove(doc);
11555
11574
  log3(`Successfully removed duplicate review: ${docId}`);
11556
11575
  } catch (error) {
@@ -11696,9 +11715,11 @@ Currently logged-in as ${this._username}.`
11696
11715
  }
11697
11716
  }
11698
11717
  async scheduleCardReview(review) {
11718
+ this._scheduledGeneration++;
11699
11719
  return scheduleCardReviewLocal(this.writeDB, review);
11700
11720
  }
11701
11721
  async removeScheduledCardReview(reviewId) {
11722
+ this._scheduledGeneration++;
11702
11723
  return removeScheduledCardReviewLocal(this.writeDB, reviewId);
11703
11724
  }
11704
11725
  async registerForClassroom(_classId, _registerAs) {