-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Lazy load commands #9519
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
Lazy load commands #9519
Changes from 4 commits
c4045a4
09435d2
f9ce44e
cfb1bcf
50ebe24
14e700b
022b505
192d3e9
6b34ff5
5c857e5
648564d
d87e4b7
d5f256f
1ab38ca
5507dcb
6194960
7e6b680
5e061f0
fcce7d0
998c2c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,36 @@ | ||
| import * as experiments from "../experiments"; | ||
| import { Command } from "../command"; | ||
|
Check failure on line 2 in src/commands/index.ts
|
||
|
|
||
| /** | ||
| * Loads all commands for our parser. | ||
| */ | ||
| export function load(client: any): any { | ||
| function loadCommand(name: string) { | ||
| const t0 = process.hrtime.bigint(); | ||
|
Check failure on line 9 in src/commands/index.ts
|
||
| const { command: cmd } = require(`./${name}`); | ||
| cmd.register(client); | ||
| const t1 = process.hrtime.bigint(); | ||
| const diffMS = (t1 - t0) / BigInt(1e6); | ||
| if (diffMS > 75) { | ||
| // NOTE: logger.debug doesn't work since it's not loaded yet. Comment out below to debug. | ||
| // console.error(`Loading ${name} took ${diffMS}ms`); | ||
| } | ||
|
|
||
| return cmd.runner(); | ||
| const load = () => { | ||
| const { command: cmd } = require(`./${name}`); | ||
| cmd.register(client); | ||
| return cmd.runner(); | ||
| }; | ||
|
|
||
| const runner = async (...args: any[]) => { | ||
| const run = load(); | ||
| return run(...args); | ||
| }; | ||
|
|
||
| // Store the load function on the runner so we can trigger it without running. | ||
| (runner as any).load = () => { | ||
| const tStart = process.hrtime.bigint(); | ||
| require(`./${name}`).command.register(client); | ||
| const tEnd = process.hrtime.bigint(); | ||
| const diff = (tEnd - tStart) / BigInt(1e6); | ||
| if (diff > 75) { | ||
|
||
| // console.error(`Loading ${name} took ${diff}ms`); | ||
|
Check failure on line 29 in src/commands/index.ts
|
||
| } | ||
| }; | ||
|
|
||
| return runner; | ||
| } | ||
joehan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const t0 = process.hrtime.bigint(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.