fix: deduplicate SSE events and debounce client reload
Build and Deploy / build-and-deploy (push) Successful in 1m39s
Build and Deploy / build-and-deploy (push) Successful in 1m39s
This commit is contained in:
+12
-1
@@ -115,7 +115,18 @@ sseHandler changeLog _request respond = do
|
||||
sent <- readIORef lastSent
|
||||
when (version > sent) $ do
|
||||
let newEntries = takeWhile (\(v, _) -> v > sent) entries
|
||||
forM_ newEntries $ \(_v, path) -> do
|
||||
-- Entries are newest-first. Deduplicate by filename,
|
||||
-- keeping the newest (first encountered) entry per file.
|
||||
let deduped =
|
||||
foldl'
|
||||
( \acc e@(_, p) ->
|
||||
if any ((== p) . snd) acc
|
||||
then acc
|
||||
else e : acc
|
||||
)
|
||||
[]
|
||||
newEntries
|
||||
forM_ deduped $ \(_v, path) -> do
|
||||
write
|
||||
( lazyByteString $
|
||||
LB.fromStrict $
|
||||
|
||||
Reference in New Issue
Block a user