detached c2c40ba

fix(services): use buffered channel for history flush to prevent blocking

commit
c2c40ba238b77f17c70da54f47614ef6bbab9da5
author
bnema · · 2025-10-23 22:06 UTC
committer
bnema · · 2025-10-24 17:33 UTC
parent
50e023b
signature
unsigned
1 file · +4 -4
M internal/services/browser.go +4 -4
@@ -49,7 +49,7 @@ type BrowserService struct {
4949 guiBundle string
5050 zoomCache sync.Map // In-memory cache: key = domain/URL, value = float64 zoom level
5151 historyQueue chan historyUpdate // Queue for batched history writes
52- historyFlushDone chan struct{} // Signal when history flush is complete
52+ historyFlushDone chan bool // Signal when history flush is complete (buffered)
5353 }
5454
5555 // ServiceName returns the service name for frontend binding
@@ -88,7 +88,7 @@ func NewBrowserService(cfg *config.Config, queries db.DatabaseQuerier) *BrowserS
8888 initialURL: "",
8989 guiBundle: "",
9090 historyQueue: make(chan historyUpdate, 100), // Buffer 100 history updates
91- historyFlushDone: make(chan struct{}),
91+ historyFlushDone: make(chan bool, 1), // Buffered to prevent blocking
9292 }
9393
9494 // Start background batch processor for history writes
@@ -428,7 +428,7 @@ func (s *BrowserService) processHistoryQueue() {
428428 if !ok {
429429 // Channel closed, flush remaining and exit
430430 flush()
431- close(s.historyFlushDone)
431+ s.historyFlushDone <- true // Send signal (non-blocking due to buffer)
432432 return
433433 }
434434 batch = append(batch, update)
@@ -446,7 +446,7 @@ func (s *BrowserService) processHistoryQueue() {
446446 // Call this during graceful shutdown.
447447 func (s *BrowserService) FlushHistoryQueue() {
448448 close(s.historyQueue)
449- <-s.historyFlushDone // Wait for flush to complete
449+ <-s.historyFlushDone // Wait for completion signal
450450 log.Printf("History queue flushed and closed")
451451 }
452452
@@ -49,7 +49,7 @@ type BrowserService struct {
49 guiBundle string49 guiBundle string
50 zoomCache sync.Map // In-memory cache: key = domain/URL, value = float64 zoom level50 zoomCache sync.Map // In-memory cache: key = domain/URL, value = float64 zoom level
51 historyQueue chan historyUpdate // Queue for batched history writes51 historyQueue chan historyUpdate // Queue for batched history writes
52- historyFlushDone chan struct{} // Signal when history flush is complete52+ historyFlushDone chan bool // Signal when history flush is complete (buffered)
53 }53 }
54 54
55 // ServiceName returns the service name for frontend binding55 // ServiceName returns the service name for frontend binding
@@ -88,7 +88,7 @@ func NewBrowserService(cfg *config.Config, queries db.DatabaseQuerier) *BrowserS
88 initialURL: "",88 initialURL: "",
89 guiBundle: "",89 guiBundle: "",
90 historyQueue: make(chan historyUpdate, 100), // Buffer 100 history updates90 historyQueue: make(chan historyUpdate, 100), // Buffer 100 history updates
91- historyFlushDone: make(chan struct{}),91+ historyFlushDone: make(chan bool, 1), // Buffered to prevent blocking
92 }92 }
93 93
94 // Start background batch processor for history writes94 // Start background batch processor for history writes
@@ -428,7 +428,7 @@ func (s *BrowserService) processHistoryQueue() {
428 if !ok {428 if !ok {
429 // Channel closed, flush remaining and exit429 // Channel closed, flush remaining and exit
430 flush()430 flush()
431- close(s.historyFlushDone)431+ s.historyFlushDone <- true // Send signal (non-blocking due to buffer)
432 return432 return
433 }433 }
434 batch = append(batch, update)434 batch = append(batch, update)
@@ -446,7 +446,7 @@ func (s *BrowserService) processHistoryQueue() {
446 // Call this during graceful shutdown.446 // Call this during graceful shutdown.
447 func (s *BrowserService) FlushHistoryQueue() {447 func (s *BrowserService) FlushHistoryQueue() {
448 close(s.historyQueue)448 close(s.historyQueue)
449- <-s.historyFlushDone // Wait for flush to complete449+ <-s.historyFlushDone // Wait for completion signal
450 log.Printf("History queue flushed and closed")450 log.Printf("History queue flushed and closed")
451 }451 }
452 452

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 8

Tags 42

↑↓ moveenter openesc close