Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(core): avoid page init when only id required #7867

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions packages/frontend/core/src/hooks/use-journal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ export const useJournalHelper = (docCollection: DocCollection) => {
const getJournalsByDate = useCallback(
(maybeDate: MaybeDate) => {
const day = dayjs(maybeDate);
return Array.from(docCollection.docs.values())
.map(blockCollection => blockCollection.getDoc())
.filter(page => {
const pageId = page.id;
if (!isPageJournal(pageId)) return false;
if (page.meta?.trash) return false;
const journalDate = adapter.getJournalPageDateString(page.id);
if (!journalDate) return false;
return day.isSame(journalDate, 'day');
});
return Array.from(docCollection.docs.values()).filter(page => {
const pageId = page.id;
if (!isPageJournal(pageId)) return false;
if (page.meta?.trash) return false;
const journalDate = adapter.getJournalPageDateString(page.id);
if (!journalDate) return false;
return day.isSame(journalDate, 'day');
});
},
[adapter, isPageJournal, docCollection.docs]
);
Expand All @@ -83,7 +81,7 @@ export const useJournalHelper = (docCollection: DocCollection) => {
const getJournalByDate = useCallback(
(maybeDate: MaybeDate) => {
const pages = getJournalsByDate(maybeDate);
if (pages.length) return pages[0];
if (pages.length) return pages[0].getDoc();
return _createJournal(maybeDate);
},
[_createJournal, getJournalsByDate]
Expand Down Expand Up @@ -140,9 +138,9 @@ export const useJournalHelper = (docCollection: DocCollection) => {
appendContentToToday,
}),
[
getJournalsByDate,
getJournalByDate,
getJournalDateString,
getJournalsByDate,
getLocalizedJournalDateString,
isPageJournal,
isPageTodayJournal,
Expand Down
Loading