diff --git a/packages/insomnia/src/common/database.ts b/packages/insomnia/src/common/database.ts index 79f74a3754..c7d79a5d51 100644 --- a/packages/insomnia/src/common/database.ts +++ b/packages/insomnia/src/common/database.ts @@ -34,7 +34,7 @@ export interface SpecificQuery { } export type ChangeType = 'insert' | 'update' | 'remove'; -export const database = { +const database = { // Get all documents of a certain type all: async function(type: string) { if (db._empty) { @@ -669,6 +669,49 @@ export const database = { }, }; +const isMainProcess = process.type === 'browser'; + +let countIsExecuting = 0; + +let startTime: undefined | number = undefined; + +let totalExecutingTime = 0; + +for (let asyncMethodName of Object.keys(database).filter(key => { + return typeof database[key] === 'function' + && key !== 'onChange' + && key !== 'offChange'; +})) { + const oriFunction = database[asyncMethodName]; + + database[asyncMethodName] = function () { + if (countIsExecuting === 0) { + if (startTime !== undefined) { + console.warn('startTime is not undefined when start'); + } + startTime = Date.now(); + } + countIsExecuting++; + return oriFunction.apply(this, arguments).finally(() => { + countIsExecuting--; + if (countIsExecuting === 0) { + if (startTime === undefined) { + console.warn('startTime is undefined when end'); + } + const time = Date.now() - startTime; + startTime = undefined; + totalExecutingTime += time; + } + }); + }; +} + +setInterval(() => { + console.log(`----------------${isMainProcess ? 'Main' : 'Renderer'} process has been executing for ${totalExecutingTime} ms----------------------`); +}, 1000); + +export { database }; + interface DB { [index: string]: NeDB; } diff --git a/packages/insomnia/src/sync/git/git-vcs.ts b/packages/insomnia/src/sync/git/git-vcs.ts index 06ed8e0d91..9d7fb5c7e0 100644 --- a/packages/insomnia/src/sync/git/git-vcs.ts +++ b/packages/insomnia/src/sync/git/git-vcs.ts @@ -5,6 +5,7 @@ import { parse } from 'yaml'; import { httpClient } from './http-client'; import { convertToPosixSep } from './path-sep'; import { gitCallbacks } from './utils'; +import { time, timeEnd } from 'console'; export interface GitAuthor { name: string; @@ -508,7 +509,9 @@ export class GitVCS { staged: { path: string; status: [git.HeadStatus, git.WorkdirStatus, git.StageStatus]; name: string }[]; unstaged: { path: string; status: [git.HeadStatus, git.WorkdirStatus, git.StageStatus]; name: string }[]; }> { + console.time('statusWithContent'); const status = await this.statusWithContent(); + console.timeEnd('statusWithContent'); const unstagedChanges = status.filter(({ workdir, stage }) => stage.status !== workdir.status); const stagedChanges = status.filter(({ head, stage }) => stage.status !== head.status); diff --git a/packages/insomnia/src/sync/git/ne-db-client.ts b/packages/insomnia/src/sync/git/ne-db-client.ts index 7c2b7e0c4f..e01ca9fc5c 100644 --- a/packages/insomnia/src/sync/git/ne-db-client.ts +++ b/packages/insomnia/src/sync/git/ne-db-client.ts @@ -36,6 +36,7 @@ export class NeDBClient { filePath: string, options?: BufferEncoding | { encoding?: BufferEncoding }, ) { + console.count('readFile'); filePath = path.normalize(filePath); options = options || {}; @@ -80,6 +81,7 @@ export class NeDBClient { } async writeFile(filePath: string, data: Buffer | string) { + console.count('writeFile'); filePath = path.normalize(filePath); const { root, id, type } = parseGitPath(filePath); @@ -110,6 +112,7 @@ export class NeDBClient { } async unlink(filePath: string) { + console.count('unlink'); filePath = path.normalize(filePath); const { id, type } = parseGitPath(filePath); @@ -130,6 +133,7 @@ export class NeDBClient { // and returns a list of all the files/folders which should be in the directory // according to the what entities are children of the workspace async readdir(filePath: string) { + console.count('readdir'); filePath = path.normalize(filePath); const { root, type, id } = parseGitPath(filePath); let docs: BaseModel[] = []; @@ -194,6 +198,7 @@ export class NeDBClient { } async stat(filePath: string) { + console.count('stat'); filePath = path.normalize(filePath); let fileBuff: Buffer | string | null = null; let dir: string[] | null = null; diff --git a/packages/insomnia/src/ui/components/dropdowns/git-sync-dropdown.tsx b/packages/insomnia/src/ui/components/dropdowns/git-sync-dropdown.tsx index f16006f093..f964f4149b 100644 --- a/packages/insomnia/src/ui/components/dropdowns/git-sync-dropdown.tsx +++ b/packages/insomnia/src/ui/components/dropdowns/git-sync-dropdown.tsx @@ -268,7 +268,7 @@ export const GitSyncDropdown: FC = ({ gitRepository, isInsomniaSyncEnable action: () => setIsGitRepoSettingsModalOpen(true), }]); - useInterval(() => { + /* useInterval(() => { gitFetchFetcher.submit( {}, { @@ -276,7 +276,7 @@ export const GitSyncDropdown: FC = ({ gitRepository, isInsomniaSyncEnable method: 'post', } ); - }, 1000 * 60 * 5); + }, 1000 * 60 * 5); */ const status = gitStatusFetcher.data?.status; diff --git a/packages/insomnia/src/ui/routes/git-actions.tsx b/packages/insomnia/src/ui/routes/git-actions.tsx index 3a04671588..94c52cd062 100644 --- a/packages/insomnia/src/ui/routes/git-actions.tsx +++ b/packages/insomnia/src/ui/routes/git-actions.tsx @@ -32,6 +32,7 @@ import { SegmentEvent, vcsSegmentEventProperties, } from '../analytics'; +import { time, timeEnd } from 'console'; // Loaders export type GitRepoLoaderData = @@ -294,6 +295,7 @@ export interface GitChangesLoaderData { export const gitChangesLoader: LoaderFunction = async ({ params, }): Promise => { + console.time('gitChangesLoader'); const { workspaceId } = params; invariant(typeof workspaceId === 'string', 'Workspace Id is required'); @@ -326,6 +328,7 @@ export const gitChangesLoader: LoaderFunction = async ({ models.workspaceMeta.updateByParentId(workspaceId, { hasUncommittedChanges, }); + console.timeEnd('gitChangesLoader'); return { branch, changes,