mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-24 05:07:06 +08:00
perf(core): avoid page init when only id required (#7867)
This commit is contained in:
@@ -63,16 +63,14 @@ export const useJournalHelper = (docCollection: DocCollection) => {
|
|||||||
const getJournalsByDate = useCallback(
|
const getJournalsByDate = useCallback(
|
||||||
(maybeDate: MaybeDate) => {
|
(maybeDate: MaybeDate) => {
|
||||||
const day = dayjs(maybeDate);
|
const day = dayjs(maybeDate);
|
||||||
return Array.from(docCollection.docs.values())
|
return Array.from(docCollection.docs.values()).filter(page => {
|
||||||
.map(blockCollection => blockCollection.getDoc())
|
const pageId = page.id;
|
||||||
.filter(page => {
|
if (!isPageJournal(pageId)) return false;
|
||||||
const pageId = page.id;
|
if (page.meta?.trash) return false;
|
||||||
if (!isPageJournal(pageId)) return false;
|
const journalDate = adapter.getJournalPageDateString(page.id);
|
||||||
if (page.meta?.trash) return false;
|
if (!journalDate) return false;
|
||||||
const journalDate = adapter.getJournalPageDateString(page.id);
|
return day.isSame(journalDate, 'day');
|
||||||
if (!journalDate) return false;
|
});
|
||||||
return day.isSame(journalDate, 'day');
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[adapter, isPageJournal, docCollection.docs]
|
[adapter, isPageJournal, docCollection.docs]
|
||||||
);
|
);
|
||||||
@@ -83,7 +81,7 @@ export const useJournalHelper = (docCollection: DocCollection) => {
|
|||||||
const getJournalByDate = useCallback(
|
const getJournalByDate = useCallback(
|
||||||
(maybeDate: MaybeDate) => {
|
(maybeDate: MaybeDate) => {
|
||||||
const pages = getJournalsByDate(maybeDate);
|
const pages = getJournalsByDate(maybeDate);
|
||||||
if (pages.length) return pages[0];
|
if (pages.length) return pages[0].getDoc();
|
||||||
return _createJournal(maybeDate);
|
return _createJournal(maybeDate);
|
||||||
},
|
},
|
||||||
[_createJournal, getJournalsByDate]
|
[_createJournal, getJournalsByDate]
|
||||||
@@ -140,9 +138,9 @@ export const useJournalHelper = (docCollection: DocCollection) => {
|
|||||||
appendContentToToday,
|
appendContentToToday,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
|
getJournalsByDate,
|
||||||
getJournalByDate,
|
getJournalByDate,
|
||||||
getJournalDateString,
|
getJournalDateString,
|
||||||
getJournalsByDate,
|
|
||||||
getLocalizedJournalDateString,
|
getLocalizedJournalDateString,
|
||||||
isPageJournal,
|
isPageJournal,
|
||||||
isPageTodayJournal,
|
isPageTodayJournal,
|
||||||
|
|||||||
Reference in New Issue
Block a user