mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 18:37:24 +00:00
perf(sidebar): share mounted row scans across review visibility checks
This commit is contained in:
@@ -18,6 +18,30 @@ export function getMountedWorktreeOptions(
|
||||
return result
|
||||
}
|
||||
|
||||
export function getMountedWorktreeOptionsById(
|
||||
worktreeIds: readonly string[],
|
||||
root: ParentNode
|
||||
): Map<string, HTMLElement[]> {
|
||||
const requested = new Set(worktreeIds)
|
||||
const result = new Map<string, HTMLElement[]>()
|
||||
if (requested.size === 0) {
|
||||
return result
|
||||
}
|
||||
root.querySelectorAll<HTMLElement>('[data-worktree-id]').forEach((element) => {
|
||||
const id = element.dataset.worktreeId
|
||||
if (id === undefined || !requested.has(id)) {
|
||||
return
|
||||
}
|
||||
const options = result.get(id)
|
||||
if (options) {
|
||||
options.push(element)
|
||||
} else {
|
||||
result.set(id, [element])
|
||||
}
|
||||
})
|
||||
return result
|
||||
}
|
||||
|
||||
export function markSidebarWorktreeActiveImmediately(
|
||||
worktreeId: string,
|
||||
primaryRowKey?: string
|
||||
|
||||
+25
-22
@@ -6,7 +6,7 @@ import type { Worktree } from '../../../../../../shared/worktree/types'
|
||||
import type { WorktreeGroupBy } from '../../../../../../shared/sidebar-list/row-types'
|
||||
import type { RenderRow } from '../listing/render-row'
|
||||
import type { WorktreeItemRow } from '../listing/renderable-rows'
|
||||
import { getMountedWorktreeOptions } from '../rows/option-dom'
|
||||
import { getMountedWorktreeOptionsById } from '../rows/option-dom'
|
||||
|
||||
export function installWorktreeVisibleRefreshVisibilityListener(onChange: () => void): () => void {
|
||||
document.addEventListener('visibilitychange', onChange)
|
||||
@@ -85,28 +85,31 @@ export function useVisiblePrRefreshReporting(args: {
|
||||
useEffect(() => {
|
||||
const update = (): void => {
|
||||
const scroll = args.scrollRef.current
|
||||
const viewport = scroll?.getBoundingClientRect()
|
||||
if (!enabled || !scroll || document.visibilityState !== 'visible') {
|
||||
publish([])
|
||||
return
|
||||
}
|
||||
const candidates = visibleReviewCardIds({
|
||||
enabled,
|
||||
renderRows: args.renderRows,
|
||||
virtualItems: args.virtualItems,
|
||||
viewportTop: scroll.scrollTop,
|
||||
viewportHeight: scroll.clientHeight
|
||||
})
|
||||
if (candidates.length === 0) {
|
||||
publish([])
|
||||
return
|
||||
}
|
||||
const viewport = scroll.getBoundingClientRect()
|
||||
const mountedOptions = getMountedWorktreeOptionsById(candidates, scroll)
|
||||
publish(
|
||||
scroll && document.visibilityState === 'visible'
|
||||
? visibleReviewCardIds({
|
||||
enabled,
|
||||
renderRows: args.renderRows,
|
||||
virtualItems: args.virtualItems,
|
||||
viewportTop: scroll.scrollTop,
|
||||
viewportHeight: scroll.clientHeight,
|
||||
isOnScreen: (id) =>
|
||||
getMountedWorktreeOptions(id, scroll).some((option) => {
|
||||
const surface = option.querySelector('[data-worktree-card-surface]')
|
||||
const bounds = (surface?.firstElementChild ?? option).getBoundingClientRect()
|
||||
return (
|
||||
viewport !== undefined &&
|
||||
bounds.height > 0 &&
|
||||
bounds.top < viewport.bottom &&
|
||||
bounds.bottom > viewport.top
|
||||
)
|
||||
})
|
||||
})
|
||||
: []
|
||||
candidates.filter((id) =>
|
||||
mountedOptions.get(id)?.some((option) => {
|
||||
const surface = option.querySelector('[data-worktree-card-surface]')
|
||||
const bounds = (surface?.firstElementChild ?? option).getBoundingClientRect()
|
||||
return bounds.height > 0 && bounds.top < viewport.bottom && bounds.bottom > viewport.top
|
||||
})
|
||||
)
|
||||
)
|
||||
}
|
||||
update()
|
||||
|
||||
Reference in New Issue
Block a user