Skip to content

Commit

Permalink
fix: empty statistcs record file will cause the endless loop
Browse files Browse the repository at this point in the history
Signed-off-by: edonyzpc <[email protected]>
  • Loading branch information
edonyzpc committed May 12, 2024
1 parent d381171 commit 88bd9d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class PluginManager extends Plugin {
}
})

// Handle the Editor Plugins
// Handle the Editor Plugins
this.registerEditorExtension([pluginField.init(() => this), statusBarEditorPlugin, sectionWordCountEditorPlugin]);

this.registerEvent(
Expand Down
17 changes: 13 additions & 4 deletions src/stats/StatsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,19 @@ export default class StatsManager {

this.today = moment().format("YYYY-MM-DD");
let counter = 1;
while (!this.vaultStats.history.hasOwnProperty(moment().subtract(counter, 'days').format("YYYY-MM-DD"))) {
counter++;
let files = 0;
const recordDays = Object.keys(this.vaultStats.history).length;
if (recordDays > 0) {
// try to iterate all of the recorded days and find the last record stat.
while (!this.vaultStats.history.hasOwnProperty(moment().subtract(counter, 'days').format("YYYY-MM-DD")) &&
counter <= recordDays) {
counter++;
}
files = this.vaultStats.history[moment().subtract(counter, 'days').format("YYYY-MM-DD")].files;
} else {
files = 0;
}
const lastRecordDay = moment().subtract(counter, 'days').format("YYYY-MM-DD");

const totalWords = await this.calcTotalWords();
const totalCharacters = await this.calcTotalCharacters();
const totalSentences = await this.calcTotalSentences();
Expand All @@ -100,7 +109,7 @@ export default class StatsManager {
characters: 0,
sentences: 0,
pages: 0,
files: this.vaultStats.history[lastRecordDay].files,
files: files,
footnotes: 0,
citations: 0,
totalWords: totalWords,
Expand Down

0 comments on commit 88bd9d7

Please sign in to comment.