Fix bd SearchIssues inefficient WHERE IN query pattern for Dolt
All checks were successful
CI / check (push) Successful in 3m25s
All checks were successful
CI / check (push) Successful in 3m25s
The Dolt backend's SearchIssues was using a two-phase query: 1. SELECT id FROM issues WHERE ... -> collect all IDs 2. SELECT * FROM issues WHERE id IN (id1, id2, ... id8000+) With 8000+ issues, this second query with 8000+ placeholders hammers Dolt CPU at 100%+. The fix changes SearchIssues to select all columns directly in the first query and scan results inline. See: hq-ihwsj Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,6 +9,15 @@ let
|
||||
# Remove after upstream fix: https://github.com/steveyegge/beads/issues/XXX
|
||||
beadsPackage = globalInputs.beads.packages.${system}.default.overrideAttrs (old: {
|
||||
vendorHash = "sha256-YU+bRLVlWtHzJ1QPzcKJ70f+ynp8lMoIeFlm+29BNPE=";
|
||||
|
||||
# Performance fix: avoid WHERE IN (8000+ IDs) query pattern that hammers Dolt CPU
|
||||
# See: hq-ihwsj - bd list uses inefficient WHERE IN (all_ids) query pattern
|
||||
# The fix changes SearchIssues to SELECT all columns directly instead of:
|
||||
# 1. SELECT id FROM issues WHERE ... -> collect IDs
|
||||
# 2. SELECT * FROM issues WHERE id IN (all_ids) -> 8000+ placeholder IN clause
|
||||
patches = (old.patches or []) ++ [
|
||||
./beads-search-query-optimization.patch
|
||||
];
|
||||
});
|
||||
|
||||
# Gastown - multi-agent workspace manager (no upstream flake.nix yet)
|
||||
@@ -125,9 +134,50 @@ let
|
||||
|
||||
# Statusline optimization: skip detached sessions and cache results
|
||||
# Reduces Dolt CPU from ~70% to ~20% by avoiding beads queries for sessions nobody is watching
|
||||
# Cache functions already exist in upstream, we just add the early-return + cache writes
|
||||
# See: https://github.com/steveyegge/gastown/issues/TBD
|
||||
substituteInPlace internal/cmd/statusline.go \
|
||||
--replace-fail \
|
||||
'"strings"' \
|
||||
'"strings"
|
||||
"time"' \
|
||||
--replace-fail \
|
||||
'var (
|
||||
statusLineSession string
|
||||
)' \
|
||||
'// statusLineCacheTTL is how long cached status output remains valid.
|
||||
const statusLineCacheTTL = 10 * time.Second
|
||||
|
||||
// statusLineCachePath returns the cache file path for a session.
|
||||
func statusLineCachePath(session string) string {
|
||||
return filepath.Join(os.TempDir(), fmt.Sprintf("gt-status-%s", session))
|
||||
}
|
||||
|
||||
// getStatusLineCache returns cached status if fresh, empty string otherwise.
|
||||
func getStatusLineCache(session string) string {
|
||||
path := statusLineCachePath(session)
|
||||
info, err := os.Stat(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
if time.Since(info.ModTime()) > statusLineCacheTTL {
|
||||
return ""
|
||||
}
|
||||
data, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(data)
|
||||
}
|
||||
|
||||
// setStatusLineCache writes status to cache file.
|
||||
func setStatusLineCache(session, status string) {
|
||||
path := statusLineCachePath(session)
|
||||
_ = os.WriteFile(path, []byte(status), 0644)
|
||||
}
|
||||
|
||||
var (
|
||||
statusLineSession string
|
||||
)' \
|
||||
--replace-fail \
|
||||
'func runStatusLine(cmd *cobra.Command, args []string) error {
|
||||
t := tmux.NewTmux()
|
||||
@@ -151,7 +201,7 @@ let
|
||||
|
||||
// Get session environment' \
|
||||
--replace-fail \
|
||||
'// Output
|
||||
' // Output
|
||||
if len(parts) > 0 {
|
||||
fmt.Print(strings.Join(parts, " | ") + " |")
|
||||
}
|
||||
@@ -159,8 +209,8 @@ let
|
||||
return nil
|
||||
}
|
||||
|
||||
// runMayorStatusLine' \
|
||||
'// Output
|
||||
func runMayorStatusLine(t *tmux.Tmux) error {' \
|
||||
' // Output
|
||||
if len(parts) > 0 {
|
||||
output := strings.Join(parts, " | ") + " |"
|
||||
if statusLineSession != "" {
|
||||
@@ -172,7 +222,7 @@ let
|
||||
return nil
|
||||
}
|
||||
|
||||
// runMayorStatusLine' \
|
||||
func runMayorStatusLine(t *tmux.Tmux) error {' \
|
||||
--replace-fail \
|
||||
'fmt.Print(strings.Join(parts, " | ") + " |")
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user