-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/async diag collect #703
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request updates the Changes
Sequence Diagram(s)sequenceDiagram
participant Ctrl as DiagnosticCtrl
participant MQTT as mqttClient
participant FileChecker
Ctrl->>MQTT: addStickySubscription("/wb-diag-collect/artifact")
MQTT-->>Ctrl: Receive message(payload)
Ctrl->>Ctrl: Parse payload (extract fullname & basename)
Ctrl->>FileChecker: Invoke fileIsOk(basename)
Suggested reviewers
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (4)
debian/changelog
(1 hunks)frontend/app/scripts/controllers/diagnosticController.js
(2 hunks)frontend/app/scripts/i18n/system/en.json
(1 hunks)frontend/app/scripts/i18n/system/ru.json
(1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
frontend/app/scripts/controllers/diagnosticController.js
[error] 79-79: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 78-78: Use let or const instead of var.
A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.
(lint/style/noVar)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Codacy Static Code Analysis
🔇 Additional comments (4)
frontend/app/scripts/controllers/diagnosticController.js (1)
2-2
: Confirm proper handling of newmqttClient
parameter.You have introduced a
mqttClient
parameter in the constructor. Verify that all upstream constructors and dependency injections properly instantiate this parameter, ensuring it is never null or undefined.debian/changelog (1)
1-5
: Changelog entry approved.No issues found in the new version entry. The asynchronous rework is noted and consistent with the PR’s objectives.
frontend/app/scripts/i18n/system/en.json (1)
6-6
: Confirm removal of the timeout error key.Removing the “timeout” entry helps declutter the error messages. Verify there are no references to it elsewhere in the codebase that may lead to undefined string lookups.
frontend/app/scripts/i18n/system/ru.json (1)
6-10
: Standardizing Collector Section and Removing Deprecated Error MessageThe updated collector title now uses standardized spacing, making it clearer and more consistent with other localization entries. Additionally, the removal of the
"timeout"
error message is in line with the asynchronous diagnostic collection, but please verify that no frontend component still references this key to avoid any missing key issues.
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) { | ||
if (msg.payload) { | ||
const data = JSON.parse(msg.payload) | ||
$scope.path = data['fullname']; | ||
$scope.basename = data['basename']; | ||
var url = getUrl(); | ||
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); | ||
} | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Consider managing sticky subscriptions gracefully.
You invoke mqttClient.addStickySubscription
without unsubscribing later. Ensure this indefinite subscription does not cause excess resource usage or memory leaks, especially if multiple subscriptions are created over time.
🧰 Tools
🪛 Biome (1.9.4)
[error] 79-79: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 78-78: Use let or const instead of var.
A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.
(lint/style/noVar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кролик прав. Стоит сделать подписку один раз, а в теле обработчика проверять $scope.collecting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@KraPete Here's how we can implement the subscription:
constructor($scope, $translate, DiagnosticProxy, errors, whenMqttReady, mqttClient) {
// ... existing code ...
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) {
if ($scope.collecting && msg.payload) {
const data = JSON.parse(msg.payload);
$scope.path = data['fullname'];
$scope.basename = data['basename'];
const url = getUrl();
fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk);
}
});
var diag = function () {
$scope.btnEnabled = false;
changeBtnText('collector.states.collecting');
$scope.collecting = true;
DiagnosticProxy.diag();
};
}
(`^´)
✏️ Learnings added
Learnt from: KraPete
PR: wirenboard/homeui#703
File: frontend/app/scripts/controllers/diagnosticController.js:73-82
Timestamp: 2025-02-21T03:55:57.764Z
Learning: In Angular controllers using MQTT, subscribe to topics once in the constructor and use scope variables to control when the subscription handler should process messages, rather than creating new subscriptions for each operation.
Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
var url = getUrl(); | ||
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
Adopt modern variable declarations and template literals.
Replacing var url = getUrl();
with a block-scoped declaration and using a template literal for building the URL improves readability and prevents accidental reassignments.
- var url = getUrl();
- fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk);
+ const url = getUrl();
+ fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk);
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
var url = getUrl(); | |
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); | |
const url = getUrl(); | |
fileIsOk(`${location.protocol}//${url}/diag/${$scope.basename}`, callbackFileIsOk); |
🧰 Tools
🪛 Biome (1.9.4)
[error] 79-79: Template literals are preferred over string concatenation.
Unsafe fix: Use a template literal.
(lint/style/useTemplate)
[error] 78-78: Use let or const instead of var.
A variable declared with var is accessible in the whole body of the function. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
See MDN web docs for more details.
Unsafe fix: Use 'const' instead.
(lint/style/noVar)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И тут кролик прав
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Давай ещё вернём обработку ошибок, как выше в коде через catch.
Ну и кролик везде прав
mqttClient.addStickySubscription('/wb-diag-collect/artifact', function (msg) { | ||
if (msg.payload) { | ||
const data = JSON.parse(msg.payload) | ||
$scope.path = data['fullname']; | ||
$scope.basename = data['basename']; | ||
var url = getUrl(); | ||
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); | ||
} | ||
} | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кролик прав. Стоит сделать подписку один раз, а в теле обработчика проверять $scope.collecting
var url = getUrl(); | ||
fileIsOk(location.protocol + '//' + url + '/diag/' + $scope.basename, callbackFileIsOk); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
И тут кролик прав
переделал бек wb-diag-collect, чтобы не стрелял rpc-таймаутом на загруженных wb
ux никак не поменялся
Summary by CodeRabbit