refactor: improve node DB state management and readiness logic#3932
Merged
Conversation
This commit refactors the node database handling within `MeshService` to improve performance and reliability during initial configuration synchronization.
Previously, each `NodeInfo` received from the device was individually written to the database, leading to multiple transactions. This could be slow and inefficient, especially on startup.
The key changes are:
- Introduced a batch update mechanism for the initial node list. Instead of writing each node to the database one by one, all nodes are now collected and saved in a single transaction when the `NodeInfoComplete` signal is received.
- The `haveNodeDB` flag has been split into two more descriptive flags:
- `isNodeDbReady`: Signals that the initial node database is synchronized and ready for use.
- `allowNodeDbWrites`: Controls when individual node updates can be written to the persistent database, which is enabled only after the initial batch-write is complete.
- `updateNodeInfo()` now includes a `withBroadcast` parameter to prevent unnecessary broadcasts and database writes during the initial batch processing.
- The `myNodeInfo` object is now updated more reliably from the `nodeRepository` flow at service start.
Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3932 +/- ##
========================================
- Coverage 0.52% 0.52% -0.01%
========================================
Files 394 394
Lines 23136 23141 +5
Branches 2933 2933
========================================
Hits 122 122
- Misses 22993 22998 +5
Partials 21 21 ☔ View full report in Codecov by Sentry. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the node database readiness and update logic in the
MeshServiceclass to improve clarity and reliability when handling node database state transitions. The main changes include renaming and splitting node DB state flags, updating the node info installation and completion process, and ensuring more robust batch updates and state transitions.resolves #3898
replaces #3899