Skip to content

Commit

Permalink
fix: #54 #56 复习时打开了没到期的笔记
Browse files Browse the repository at this point in the history
  • Loading branch information
Newdea committed Jun 23, 2024
1 parent c79d0a2 commit 27109e5
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 90 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. Dates are d

Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

## [1.12.4.6]

- fix: #54 #56 复习时打开了没到期的笔记

## [1.12.4.5]

- feat: 同步原插件最新分支sync upsteam branch
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "obsidian-spaced-repetition-recall",
"name": "Spaced Repetition Recall",
"version": "1.12.4.5",
"version": "1.12.4.6",
"minAppVersion": "0.15.4",
"description": "Fight the forgetting curve by reviewing flashcards & entire notes.",
"author": "Newdea",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "obsidian-spaced-repetition",
"version": "1.12.4.5",
"version": "1.12.4.6",
"description": "Fight the forgetting curve by reviewing flashcards & entire notes.",
"main": "main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/Card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class Card {
} else if (this.hasSchedule) {
if (
this.scheduleInfo.dueDate.isSameOrBefore(globalDateProvider.today) &&
Object.keys(Queue.getInstance().toDayLatterQueue).includes(this.Id?.toString())
Queue.getInstance().isInLaterQueue(this?.Id)
) {
notBury = true;
}
Expand Down
20 changes: 16 additions & 4 deletions src/ReviewDeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ export class ReviewDeck {

// sort scheduled notes by date & within those days, sort them by importance
this.scheduledNotes = this.scheduledNotes.sort((a: SchedNote, b: SchedNote) => {
const result = a.dueUnix - b.dueUnix;
const adue = isDue(a) ? -1 : 1;
const bdue = isDue(b) ? 1 : -1;
let result = adue + bdue;
if (result != 0) {
return result;
}
result = a.dueUnix - b.dueUnix;
if (result != 0) {
return result;
}
Expand All @@ -45,8 +51,14 @@ export class ReviewDeck {
}

get dueNotesCount(): number {
return this.scheduledNotes.filter((snote) => {
return snote.item?.isDue || snote.dueUnix <= globalDateProvider.endofToday.valueOf();
}).length;
return this.scheduledNotes.filter(isDue).length;
}
}

function isDue(snote: SchedNote): boolean {
if (Object.prototype.hasOwnProperty.call(snote, "item")) {
return snote.item.isDue;
} else {
return snote.dueUnix <= globalDateProvider.endofToday.valueOf();
}
}
4 changes: 1 addition & 3 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default class Commands {
tkfile,
noteDelayed: this.plugin.noteStats.delayedDays.dict,
// decks: deck.scheduledNotes.map((sn) => [sn.note.path, sn.item]),
que: store.data.queues.toDayLatterQueue,
que: store.data.queues.toDayLaterQueue,
});
new ItemInfoModal(plugin.data.settings, file).open();
}
Expand Down Expand Up @@ -154,8 +154,6 @@ export default class Commands {
// console.log("There are " + plugin.store.data.queue.length + " items in queue.");
// console.log(plugin.store.data.newAdded + " new where added to today.");
// console.log("repeatQueue: " + plugin.store.data.repeatQueue);
// console.log("cardQueue: " + plugin.store.data.cardQueue);
// console.log("cardRepeatQueue: " + plugin.store.data.cardRepeatQueue);
// },
// });

Expand Down
5 changes: 1 addition & 4 deletions src/dataStore/itemToDecks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ export class ItemToDecks {
// const queue = store.data.queues;
const ind = store.getFileIndex(note.path);
const trackedFile = store.getTrackedFile(note.path);
const fileid = store.getTrackedFile(note.path).noteID;
const item = store.getItembyID(fileid);
const item = store.getNoteItem(note.path);

if (item == null) {
// store._updateItem(fileid, ind, RPITEMTYPE.NOTE, rdeck.deckName);
Expand All @@ -124,8 +123,6 @@ export class ItemToDecks {
if (!trackedFile.isDefault && !item.isTracked) {
item.setTracked(ind);
}
const latterQue = store.data.queues.toDayLatterQueue;
delete latterQue[fileid];

if (item.hasDue) {
rdeck.scheduledNotes.push({
Expand Down
83 changes: 26 additions & 57 deletions src/dataStore/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,9 @@ export interface IQueue {
* @type {number[]}
*/
repeatQueue: number[];
/**
* @type {number[]}
*/
cardQueue: number[];
/**
* @type {number[]}
*/
cardRepeatQueue: number[];

toDayAllQueue: Record<number, string>;
toDayLatterQueue: Record<number, string>;
toDayLaterQueue: Record<number, string>;

/**
* @type {number}
Expand All @@ -44,16 +37,9 @@ export const DEFAULT_QUEUE_DATA: IQueue = {
* @type {number[]}
*/
repeatQueue: [],
/**
* @type {number[]}
*/
cardQueue: [],
/**
* @type {number[]}
*/
cardRepeatQueue: [],

toDayAllQueue: {},
toDayLatterQueue: {},
toDayLaterQueue: {},
/**
* @type {number}
*/
Expand All @@ -70,22 +56,16 @@ export class Queue implements IQueue {
static instance: Queue;
/**
* @type {number[]}
* e.g. review: [1,2,3]
*/
queue: Record<string, number[]>;
/**
* @type {number[]}
*/
repeatQueue: number[];
/**
* @type {number[]}
*/
cardQueue: number[];
/**
* @type {number[]}
*/
cardRepeatQueue: number[];

toDayAllQueue: Record<number, string>;
toDayLatterQueue: Record<number, string>;
toDayLaterQueue: Record<number, string>;

// maxNewPerDay: number;
lastQueue: number;
Expand All @@ -109,10 +89,8 @@ export class Queue implements IQueue {
constructor() {
this.queue = {};
this.repeatQueue = [];
this.cardQueue = [];
this.cardRepeatQueue = [];
this.toDayAllQueue = {};
this.toDayLatterQueue = {};
this.toDayLaterQueue = {};
Queue.instance = this;
}

Expand All @@ -130,7 +108,11 @@ export class Queue implements IQueue {
}
return this.queue[key]?.length ?? 0;
}
todaylatterSize(): number {
get laterSize(): number {
const len = Object.keys(this.toDayLaterQueue).length;
if (len) {
return len;
}
const keys = Object.keys(this.queue);
keys.remove(KEY_ALL);
return keys
Expand Down Expand Up @@ -183,8 +165,6 @@ export class Queue implements IQueue {

let oldAdd = 0;
let newAdd = 0;
let oldAdd_card = 0;
let newAdd_card = 0;

let untrackedFiles = 0;
let removedItems = 0;
Expand All @@ -208,20 +188,7 @@ export class Queue implements IQueue {
}),
);
const validItems = store.items.filter((item) => item != null && item.isTracked);
validItems
.filter((item) => item.isCard)
.forEach((item) => {
if (item.isNew) {
// This is a new item.
if (maxNew == -1 || this.newAdded < maxNew) {
this.newAdded += 1;
newAdd_card += this.push(this.cardQueue, item.ID);
}
} else if (item.nextReview <= now.getTime()) {
this.remove(item, this.cardRepeatQueue);
oldAdd_card += this.push(this.cardQueue, item.ID);
}
});

validItems
.filter((item) => !item.isCard)
.forEach(async (item) => {
Expand Down Expand Up @@ -304,10 +271,8 @@ export class Queue implements IQueue {
if (queue == null) {
this.queue = {};
this.repeatQueue = [];
this.cardQueue = [];
this.cardRepeatQueue = [];
this.toDayAllQueue = {};
this.toDayLatterQueue = {};
this.toDayLaterQueue = {};
console.debug("all queue are cleared!");
} else if (isArray(queue)) {
queue = [];
Expand All @@ -326,6 +291,9 @@ export class Queue implements IQueue {
return queue?.includes(id) ?? false;
}

isInLaterQueue(id: number): boolean {
return Object.keys(this.toDayLaterQueue).includes(id.toString());
}
InitQIfMissing(key: string, queueR?: Record<string, number[]>): void {
if (!this.hasQueue(key, queueR)) queueR[key] = [];
}
Expand All @@ -344,7 +312,7 @@ export class Queue implements IQueue {
* @returns {boolean}
*/
isInRepeatQueue(item: number): boolean {
return this.repeatQueue.includes(item) || this.cardRepeatQueue.includes(item);
return this.repeatQueue.includes(item);
}

updateWhenReview(item: RepetitionItem, correct: boolean, repeatItems: boolean) {
Expand All @@ -356,19 +324,20 @@ export class Queue implements IQueue {
if (repeatItems && !correct) {
this.push(this.repeatQueue, item.ID); // Re-add until correct.
} else {
// update this.toDayLatterQueue
// update this.toDayLaterQueue
const store = DataStore.getInstance();
delete this.toDayLaterQueue[item.ID];
if (item.nextReview <= globalDateProvider.endofToday.valueOf()) {
this.toDayLatterQueue[item.ID] = item.deckName;
this.toDayLaterQueue[item.ID] = item.deckName;
}
getKeysPreserveType(this.toDayLatterQueue)
getKeysPreserveType(this.toDayLaterQueue)
.map((idStr) => {
const id: number = Number(idStr);
return store.getItembyID(id);
})
.forEach((item) => {
if (item.nextReview - Date.now() < 0) {
delete this.toDayLatterQueue[item.ID];
delete this.toDayLaterQueue[item.ID];
}
});
}
Expand All @@ -384,8 +353,8 @@ export class Queue implements IQueue {
this.remove(item, this.queue[KEY_ALL]);
}

if (this.toDayLatterQueue[item.ID] !== null) {
delete this.toDayLatterQueue[item.ID];
if (this.toDayLaterQueue[item.ID] !== null) {
delete this.toDayLaterQueue[item.ID];
}
} else {
if (this.isQueued(queue, item.ID)) {
Expand Down
25 changes: 9 additions & 16 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,9 @@ export default class SRPlugin extends Plugin {

const now = window.moment(Date.now());
Object.values(this.reviewDecks).forEach((reviewDeck: ReviewDeck) => {
this.dueNotesCount += reviewDeck.dueNotesCount;
this.noteStats.newCount += reviewDeck.newNotes.length;
reviewDeck.scheduledNotes.forEach((scheduledNote: SchedNote) => {
if (scheduledNote.dueUnix <= now.valueOf()) {
this.dueNotesCount++;
}

const nDays: number = Math.ceil(
(scheduledNote.dueUnix - now.valueOf()) / (24 * 3600 * 1000),
);
Expand All @@ -552,7 +550,6 @@ export default class SRPlugin extends Plugin {
this.dueDatesNotes[nDays]++;
this.noteStats.update(nDays, scheduledNote.interval, scheduledNote.ease);
});
this.noteStats.newCount += reviewDeck.newNotes.length;

reviewDeck.sortNotes(this.linkRank.pageranks);
});
Expand Down Expand Up @@ -666,7 +663,6 @@ export default class SRPlugin extends Plugin {
);
interval = schedObj.interval;
ease = schedObj.ease;
this.easeByPath.setEaseForPath(note.path, ease);

const due = window.moment(now + interval * 24 * 3600 * 1000);
const dueString: string = due.format("YYYY-MM-DD");
Expand Down Expand Up @@ -733,9 +729,9 @@ export default class SRPlugin extends Plugin {

this.updateAndSortDueNotes();

if(!this.data.settings.reviewResponseFloatBar){
if (!this.data.settings.reviewResponseFloatBar) {
new Notice(t("RESPONSE_RECEIVED"));
}
}

if (this.data.settings.autoNextNote) {
if (!this.lastSelectedReviewDeck) {
Expand Down Expand Up @@ -781,10 +777,7 @@ export default class SRPlugin extends Plugin {
let index = -1;

const isPreviewUndueNote = (item: RepetitionItem) => {
return (
item.nextReview > Date.now() &&
!Object.keys(this.store.data.queues.toDayLatterQueue).includes(item.ID.toString())
);
return item.nextReview > Date.now() && !Queue.getInstance().isInLaterQueue(item.ID);
};
const fShowItemInfo = (item: RepetitionItem, msg: string) => {
if (this.data.settings.dataLocation !== DataLocation.SaveOnNoteFile) {
Expand All @@ -795,11 +788,11 @@ export default class SRPlugin extends Plugin {
if (calcDueCnt !== deck.dueNotesCount) {
debug(
"check cnt",
msg,
0,
deck,
msg,
`${deck.deckName} due cnt error: calc ${calcDueCnt}, dnc: ${deck.dueNotesCount}`,
);
console.debug("schedNotes:", deck.scheduledNotes);
}
const id = "obsidian-spaced-repetition-recall:view-item-info";
// eslint-disable-next-line
Expand Down Expand Up @@ -864,7 +857,7 @@ export default class SRPlugin extends Plugin {
}
}

ReviewNote.nextReviewNotice(Queue.getInstance().toDayLatterQueue);
ReviewNote.nextReviewNotice(Queue.getInstance().laterSize);

this.reviewFloatBar.selfDestruct();
this.reviewQueueView.redraw();
Expand Down Expand Up @@ -943,7 +936,7 @@ export default class SRPlugin extends Plugin {
updateStatusBar() {
this.statusBar.setText(
t("STATUS_BAR", {
dueNotesCount: this.noteStats.onDueCount + this.store.data.queues.todaylatterSize(), // this.dueNotesCount,
dueNotesCount: this.noteStats.onDueCount, // this.dueNotesCount, + this.store.data.queues.todaylatterSize()
dueFlashcardsCount: this.remainingDeckTree.getDistinctCardCount(
CardListType.All,
true,
Expand Down
6 changes: 3 additions & 3 deletions src/reviewNote/review-note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ReviewNote {
return;
}

this.nextReviewNotice(store.data.queues.toDayLatterQueue);
this.nextReviewNotice(store.data.queues.laterSize);

// plugin.updateStatusBar();

Expand Down Expand Up @@ -214,8 +214,8 @@ export class ReviewNote {
return minNextView;
}

static nextReviewNotice(toDayLatterQueue: Record<number, string>) {
if (this.minNextView > 0 && Object.keys(toDayLatterQueue).length > 0) {
static nextReviewNotice(laterSize: number) {
if (this.minNextView > 0 && laterSize > 0) {
const now = Date.now();
const interval = Math.round((this.minNextView - now) / 1000 / 60);
if (interval < 60) {
Expand Down

0 comments on commit 27109e5

Please sign in to comment.