Skip to content

Commit

Permalink
feat: apm
Browse files Browse the repository at this point in the history
Signed-off-by: Innei <i@innei.in>
  • Loading branch information
Innei committed Sep 11, 2024
1 parent c193cc1 commit 602f50a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 0 additions & 3 deletions src/renderer/src/initialize/hydrate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ export const setHydrated = (v: boolean) => {
}

export const hydrateDatabaseToStore = async () => {
appLog("Hydrate database data to store task start...")

async function hydrate() {
const now = Date.now()
await Promise.all([hydrateFeed(), hydrateSubscription(), hydrateFeedUnread(), hydrateEntry()])

window.__dbIsReady = true
const costTime = Date.now() - now
appLog("Hydrate data done,", `${costTime}ms`)

return costTime
}
Expand Down
22 changes: 16 additions & 6 deletions src/renderer/src/initialize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const initializeApp = async () => {
// Set Environment
document.documentElement.dataset.buildType = isElectronBuild ? "electron" : "web"

doMigration()
apm("migration", doMigration)

// Initialize dayjs
dayjs.extend(duration)
Expand Down Expand Up @@ -83,23 +83,25 @@ export const initializeApp = async () => {
toast,
})

hydrateSettings()
apm("hydrateSettings", hydrateSettings)

settingSyncQueue.init()
settingSyncQueue.syncLocal()
apm("setting sync", () => {
settingSyncQueue.init()
settingSyncQueue.syncLocal()
})

// should after hydrateSettings
const { dataPersist: enabledDataPersist, sendAnonymousData } = getGeneralSettings()

initSentry()
await initI18n()
await apm("i18n", initI18n)

if (sendAnonymousData) initPostHog()

let dataHydratedTime: undefined | number
// Initialize the database
if (enabledDataPersist) {
dataHydratedTime = await hydrateDatabaseToStore()
dataHydratedTime = await apm("hydrateDatabaseToStore", hydrateDatabaseToStore)
CleanerService.cleanOutdatedData()
}

Expand All @@ -122,3 +124,11 @@ export const initializeApp = async () => {
}

import.meta.hot?.dispose(cleanup)

const apm = async (label: string, fn: () => Promise<any> | any) => {
const start = Date.now()
const result = await fn()
const end = Date.now()
appLog(`${label} took ${end - start}ms`)
return result
}

0 comments on commit 602f50a

Please sign in to comment.