Skip to content

Commit cd74277

Browse files
committed
Improves graph selection perf
1 parent 3d184e3 commit cd74277

File tree

5 files changed

+300
-224
lines changed

5 files changed

+300
-224
lines changed

src/system/object.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,23 +131,52 @@ export function paths(o: Record<string, any>, path?: string): string[] {
131131
}
132132

133133
export function updateRecordValue<T>(
134-
obj: Record<string, T> | undefined,
134+
o: Record<string, T> | undefined,
135135
key: string,
136136
value: T | undefined,
137137
): Record<string, T> {
138-
if (obj == null) {
139-
obj = Object.create(null) as Record<string, T>;
138+
if (o == null) {
139+
o = Object.create(null) as Record<string, T>;
140140
}
141141

142142
if (value != null && (typeof value !== 'boolean' || value)) {
143143
if (typeof value === 'object') {
144-
obj[key] = { ...value };
144+
o[key] = { ...value };
145145
} else {
146-
obj[key] = value;
146+
o[key] = value;
147147
}
148148
} else {
149-
const { [key]: _, ...rest } = obj;
150-
obj = rest;
149+
const { [key]: _, ...rest } = o;
150+
o = rest;
151151
}
152-
return obj;
152+
return o;
153+
}
154+
155+
/**
156+
* Efficiently checks if an object has at least one own enumerable property
157+
* @param o - The object to check
158+
* @returns true if the object has at least one own enumerable property, false otherwise
159+
*/
160+
export function hasKeys(o: Record<string, any> | null | undefined): boolean {
161+
for (const k in o) {
162+
if (Object.hasOwn(o, k)) return true;
163+
}
164+
return false;
165+
}
166+
167+
/**
168+
* Efficiently checks if an object has at least the specified number of truthy values (or at least one if not specified)
169+
* @param o - The object to check (typically a Record<string, boolean>)
170+
* @param required - The minimum number of truthy values required (default: 1)
171+
* @returns true if the object has at least the required number of properties with truthy values
172+
*/
173+
export function hasTruthyKeys(o: Record<string, any> | null | undefined, required: number = 1): boolean {
174+
let count = 0;
175+
for (const k in o) {
176+
if (Object.hasOwn(o, k) && o[k]) {
177+
count++;
178+
if (count >= required) return true; // Early exit once we know we have enough
179+
}
180+
}
181+
return count >= required;
153182
}

src/webviews/apps/plus/graph/graph-header.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
385385
this.graphState.searching = false;
386386
}
387387

388-
@debounce(250)
388+
@debounce(500)
389389
private handleSearchInput(e: CustomEvent<SearchQuery>) {
390390
this.graphState.filter = e.detail;
391391
void this.handleSearch();
@@ -530,7 +530,7 @@ export class GlGraphHeader extends SignalWatcher(LitElement) {
530530
let timeout: ReturnType<typeof setTimeout> | undefined = setTimeout(() => {
531531
timeout = undefined;
532532
this.graphState.loading = true;
533-
}, 500);
533+
}, 250);
534534

535535
const ensureCore = async () => {
536536
const e = await this.onEnsureRowPromise(id, false);

0 commit comments

Comments
 (0)