Update throttler to 700ms in IndexManager.java#15501
Update throttler to 700ms in IndexManager.java#15501ThiloteE wants to merge 1 commit intoJabRef:mainfrom
Conversation
Review Summary by QodoIncrease index throttle delay to 700ms
WalkthroughsDescription• Increases index update throttle delay from 200ms to 700ms • Accommodates average typing speeds for better indexing performance • Prevents excessive indexing triggers during rapid text input Diagramflowchart LR
A["IndexManager initialization"] -- "createThrottler parameter" --> B["200ms throttle"]
B -- "updated to" --> C["700ms throttle"]
C -- "reduces indexing frequency" --> D["Better performance"]
File Changes1. jablib/src/main/java/org/jabref/logic/search/IndexManager.java
|
Code Review by Qodo
1. Throttler not stopped on close
|
| this.bibFieldsSearcher = new BibFieldsSearcher(postgreServer.getConnection(), bibFieldsIndexer.getTable()); | ||
| this.linkedFilesSearcher = new LinkedFilesSearcher(databaseContext, linkedFilesIndexer, preferences.getFilePreferences()); | ||
| this.indexUpdateThrottler = taskExecutor.createThrottler(200); | ||
| this.indexUpdateThrottler = taskExecutor.createThrottler(700); |
There was a problem hiding this comment.
1. Throttler not stopped on close 🐞 Bug ☼ Reliability
IndexManager.updateEntry schedules delayed indexing via indexUpdateThrottler, but IndexManager.close()/closeAndWait() never cancel or shut down the throttler. With the new 700ms delay, scheduled updates are more likely to run after bibFieldsIndexer/linkedFilesIndexer are closed, producing SQL errors and leaking the throttler’s ScheduledThreadPoolExecutor thread.
Agent Prompt
## Issue description
`IndexManager` schedules delayed indexing work via `indexUpdateThrottler`, but `close()` / `closeAndWait()` never cancel or shut down the throttler. After increasing the delay to 700ms, there is a larger window where a scheduled task can execute after the indexers have been closed, resulting in indexing work running against closed resources (e.g., closed JDBC connection) and leaving the throttler thread alive.
## Issue Context
- `updateEntry(...)` uses `indexUpdateThrottler.schedule(...)` to execute indexing later.
- `DelayTaskThrottler` owns a `ScheduledThreadPoolExecutor` that must be shut down.
- `IndexManager.close()` is called when a library tab is closed / during save-as, without shutting down the shared `TaskExecutor`.
## Fix Focus Areas
- Add throttler cleanup in `IndexManager.close()` and `IndexManager.closeAndWait()` (cancel pending work and shut down the throttler, ideally without blocking the UI thread in `close()`).
- Optionally guard `updateEntry(...)` with a `closed` flag to avoid scheduling after close.
### Suggested approach
- In `close()`:
- `indexUpdateThrottler.cancel();`
- Offload `indexUpdateThrottler.shutdown()` to a background executor (to avoid up to ~15s blocking from `awaitTermination`).
- In `closeAndWait()`:
- `indexUpdateThrottler.cancel();`
- Call `indexUpdateThrottler.shutdown()` directly (since this path is explicitly waiting).
## Fix Focus Areas (code pointers)
- jablib/src/main/java/org/jabref/logic/search/IndexManager.java[170-223]
- jablib/src/main/java/org/jabref/logic/search/IndexManager.java[237-249]
- jablib/src/main/java/org/jabref/logic/util/DelayTaskThrottler.java[36-75]
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools
Related issues and pull requests
Follow up to #15289 (comment)
PR Description
Delays indexing for 700ms.
Reasoning:
Steps to test
Expected result: See that indexing is delayed.
Checklist
CHANGELOG.mdin a way that can be understood by the average user (if change is visible to the user)