Skip to content

Commit

Permalink
daily notes performance fix
Browse files Browse the repository at this point in the history
  • Loading branch information
teaqu committed Sep 23, 2022
1 parent 3a339e5 commit d384432
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
20 changes: 9 additions & 11 deletions src/file.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import moment from 'moment';
import { Vault, normalizePath } from 'obsidian';
import { DAY_PLANNER_DEFAULT_CONTENT, DAY_PLANNER_FILENAME } from './constants';
import MomentDateRegex from './moment-date-regex';
import { DayPlannerSettings, DayPlannerMode, NoteForDateQuery, NoteForDate } from './settings';
import { appHasDailyNotesPluginLoaded, getAllDailyNotes, getDailyNote } from 'obsidian-daily-notes-interface';
import { appHasDailyNotesPluginLoaded, getDailyNoteSettings } from 'obsidian-daily-notes-interface';

export default class DayPlannerFile {
vault: Vault;
Expand All @@ -19,16 +18,15 @@ export default class DayPlannerFile {
}


hasTodayNote(): boolean {
async hasTodayNote(): Promise<boolean> {
if (this.settings.mode == DayPlannerMode.Daily && appHasDailyNotesPluginLoaded()) {
const date = moment();
let note = getDailyNote(date, getAllDailyNotes());
if (note) {
const noteForDate = new NoteForDate(
this.vault.getRoot().path + note.path,
new Date().toDateString()
);
this.settings.notesToDates.push(noteForDate);
const date = new Date();
const { folder, format } = getDailyNoteSettings();
const filename = this.momentDateRegex.getMoment(date, format) + '.md';
const path = normalizePath(folder + '/' + filename);
if (await this.vault.adapter.exists(path)) {
const noteForDate = new NoteForDate(path, date.toDateString());
this.settings.notesToDates = [noteForDate];
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class DayPlanner extends Plugin {
this.registerInterval(
window.setInterval(async () => {
try {
if(this.file.hasTodayNote()){
if(await this.file.hasTodayNote()){
// console.log('Active note found, starting file processing')
const planSummary = await this.plannerMD.parseDayPlanner();
planSummary.calculate();
Expand Down

0 comments on commit d384432

Please sign in to comment.