Skip to content

refactor: use shared nchan publish function#2310

Merged
limetech merged 1 commit into
masterfrom
refactor-nchan-publish
Jul 27, 2025
Merged

refactor: use shared nchan publish function#2310
limetech merged 1 commit into
masterfrom
refactor-nchan-publish

Conversation

@ljm42

@ljm42 ljm42 commented Jul 24, 2025

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • Refactor
    • Streamlined message publishing across multiple scripts by replacing manual HTTP POST requests with a unified publish mechanism. This results in more efficient and maintainable message handling for plugin and VM operations.
  • Chores
    • Updated scripts to include a shared publish module, improving internal consistency and reducing code duplication. No changes to user-facing functionality or command outputs.

@coderabbitai

coderabbitai Bot commented Jul 24, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This change refactors multiple scripts to replace manual cURL-based HTTP POST requests to local Unix socket endpoints with calls to a new publish function, imported from a shared publish.php file. The internal logic of the write function in each script is simplified, delegating message dispatch to the publish abstraction.

Changes

File(s) Change Summary
emhttp/plugins/dynamix.docker.manager/scripts/container_size
emhttp/plugins/dynamix.docker.manager/scripts/update_container
Replaced cURL-based HTTP POST in write with calls to publish function; included publish.php.
emhttp/plugins/dynamix.plugin.manager/scripts/checkall
emhttp/plugins/dynamix.plugin.manager/scripts/language
emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin
emhttp/plugins/dynamix.plugin.manager/scripts/plugin
Replaced cURL-based HTTP POST in write with publish calls; included publish.php; fallback echo unchanged.
emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php
emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php
Replaced cURL-based HTTP POST in write with publish calls; included publish.php.
emhttp/plugins/dynamix/scripts/install_key
emhttp/plugins/dynamix/scripts/newperms
emhttp/plugins/dynamix/scripts/ssd_trim
Set $docroot if unset, included publish.php, replaced cURL POST in write with publish calls.

Sequence Diagram(s)

sequenceDiagram
    participant Script
    participant publish.php
    participant MessageBroker

    Script->>publish.php: require 'publish.php'
    loop For each message
        Script->>publish.php: publish(topic, message)
        publish.php->>MessageBroker: Dispatch message to topic
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • fix: diagnostics improvements #2163: Refactors the write function in various scripts to use the centralized publish function instead of manual cURL-based HTTP POST requests, mirroring the pattern in this PR.

Suggested labels

7.2

Poem

A bunny hopped through lines of code,
Where cURL once sent its heavy load.
Now publish leaps with nimble feet,
Making message hops so neat!
Simpler scripts, less tangled thread,
The carrot’s near—just up ahead! 🥕

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 092557f and 6d6862f.

📒 Files selected for processing (11)
  • emhttp/plugins/dynamix.docker.manager/scripts/container_size (2 hunks)
  • emhttp/plugins/dynamix.docker.manager/scripts/update_container (2 hunks)
  • emhttp/plugins/dynamix.plugin.manager/scripts/checkall (1 hunks)
  • emhttp/plugins/dynamix.plugin.manager/scripts/language (2 hunks)
  • emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin (2 hunks)
  • emhttp/plugins/dynamix.plugin.manager/scripts/plugin (2 hunks)
  • emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php (1 hunks)
  • emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php (1 hunks)
  • emhttp/plugins/dynamix/scripts/install_key (1 hunks)
  • emhttp/plugins/dynamix/scripts/newperms (1 hunks)
  • emhttp/plugins/dynamix/scripts/ssd_trim (1 hunks)
🧰 Additional context used
🧠 Learnings (9)
emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin (2)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

emhttp/plugins/dynamix.plugin.manager/scripts/language (4)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: dlandon
PR: #2035
File: etc/rc.d/rc.rsyslogd:48-50
Timestamp: 2025-02-27T21:53:37.589Z
Learning: For the unraid/webgui project, simple error handling is preferred over extensive error checking in shell scripts. The copy operation for configuration files like in rc.rsyslogd doesn't require additional error logging, permission checks, or return statements.

Learnt from: SimonFair
PR: #1992
File: emhttp/plugins/dynamix/include/CPUset.php:0-0
Timestamp: 2025-02-01T15:12:16.914Z
Learning: In the unRAID WebGUI, button text should be wrapped in _() for translation support and htmlspecialchars() for security, with a preference for using ternary operators for simple conditional text assignments.

emhttp/plugins/dynamix/scripts/install_key (2)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

emhttp/plugins/dynamix.plugin.manager/scripts/plugin (2)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

emhttp/plugins/dynamix.docker.manager/scripts/container_size (5)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: Squidly271
PR: #2293
File: emhttp/plugins/dynamix.docker.manager/include/Helpers.php:302-304
Timestamp: 2025-07-11T17:24:33.977Z
Learning: In the Unraid WebGUI Docker manager (emhttp/plugins/dynamix.docker.manager/include/Helpers.php), the xmlSecurity() function call is intentionally commented out to allow users to include < and > characters in their Docker template variables on their own servers. Default templates still explicitly disallow tags, but users can customize templates as needed in their self-hosted environment.

Learnt from: SimonFair
PR: #1992
File: emhttp/plugins/dynamix/include/CPUset.php:0-0
Timestamp: 2025-02-01T15:12:16.914Z
Learning: In the unRAID WebGUI, button text should be wrapped in _() for translation support and htmlspecialchars() for security, with a preference for using ternary operators for simple conditional text assignments.

Learnt from: SimonFair
PR: #1992
File: emhttp/plugins/dynamix/include/CPUset.php:0-0
Timestamp: 2025-02-01T15:12:16.914Z
Learning: In the unRAID WebGUI, when both translation and HTML escaping are needed, always apply translation (_()) first, then escape the translated text with htmlspecialchars() to ensure proper handling of translation placeholders.

emhttp/plugins/dynamix.docker.manager/scripts/update_container (3)

Learnt from: Squidly271
PR: #2293
File: emhttp/plugins/dynamix.docker.manager/include/Helpers.php:302-304
Timestamp: 2025-07-11T17:24:33.977Z
Learning: In the Unraid WebGUI Docker manager (emhttp/plugins/dynamix.docker.manager/include/Helpers.php), the xmlSecurity() function call is intentionally commented out to allow users to include < and > characters in their Docker template variables on their own servers. Default templates still explicitly disallow tags, but users can customize templates as needed in their self-hosted environment.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

Learnt from: Squidly271
PR: #2264
File: emhttp/plugins/dynamix/include/.login.php:0-0
Timestamp: 2025-06-18T17:09:35.579Z
Learning: In the Unraid webGUI login system (emhttp/plugins/dynamix/include/.login.php), the cooldown timer restarting on page reload during the cooldown period is intentional behavior, not a bug. When a form is resubmitted during cooldown, the timer should restart to provide consistent user feedback.

emhttp/plugins/dynamix/scripts/ssd_trim (2)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: SimonFair
PR: #1992
File: emhttp/plugins/dynamix/include/CPUset.php:0-0
Timestamp: 2025-02-01T15:12:16.914Z
Learning: In the unRAID WebGUI, button text should be wrapped in _() for translation support and htmlspecialchars() for security, with a preference for using ternary operators for simple conditional text assignments.

emhttp/plugins/dynamix.plugin.manager/scripts/checkall (2)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

emhttp/plugins/dynamix/scripts/newperms (3)

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php:13-19
Timestamp: 2025-03-27T22:04:34.550Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/web-components-extractor.php is synced from another repository and should not be modified directly in the webgui repository.

Learnt from: zackspear
PR: #2099
File: emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php:58-74
Timestamp: 2025-03-27T22:04:00.594Z
Learning: The file emhttp/plugins/dynamix.my.servers/include/activation-code-extractor.php is synced from a different repository, and modifications should not be suggested in this repository's context. Changes should be proposed in the source repository instead.

Learnt from: dlandon
PR: #2035
File: etc/rc.d/rc.rsyslogd:48-50
Timestamp: 2025-02-27T21:53:37.589Z
Learning: For the unraid/webgui project, simple error handling is preferred over extensive error checking in shell scripts. The copy operation for configuration files like in rc.rsyslogd doesn't require additional error logging, permission checks, or return statements.

🧬 Code Graph Analysis (2)
emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php (2)
emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php (1)
  • write (26-30)
emhttp/plugins/dynamix/include/publish.php (1)
  • publish (26-70)
emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php (2)
emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php (1)
  • write (26-30)
emhttp/plugins/dynamix/include/publish.php (1)
  • publish (26-70)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (22)
emhttp/plugins/dynamix/scripts/newperms (1)

20-25: LGTM: Clean refactor to centralized publish function

The changes correctly implement the refactor pattern:

  • Proper $docroot initialization with fallback
  • Clean inclusion of publish.php
  • Simplified write function using the centralized publish('plugins', $message) approach

This maintains backward compatibility while removing manual cURL management.

emhttp/plugins/dynamix.plugin.manager/scripts/checkall (2)

23-23: LGTM: Consistent refactor implementation

The inclusion of publish.php aligns with the broader refactor to centralize message publishing across the codebase.


31-31: LGTM: Simplified message publishing

The replacement of manual cURL logic with publish('plugins', $message) correctly delegates message dispatch to the centralized function while maintaining the same external behavior.

emhttp/plugins/dynamix.plugin.manager/scripts/multiplugin (2)

15-17: LGTM: Well-structured refactor implementation

The changes follow the established pattern:

  • Proper $docroot initialization with fallback to /usr/local/emhttp
  • Clean inclusion of the centralized publish.php file

This maintains consistency across the codebase refactor.


27-27: LGTM: Correct delegation to publish function

The write function correctly uses publish('plugins', $message) to replace the previous manual cURL implementation, maintaining the same external interface while simplifying internal logic.

emhttp/plugins/dynamix.vm.manager/scripts/VMClone.php (2)

24-24: LGTM: Consistent include pattern

The inclusion of publish.php follows the established refactor pattern across the codebase.


26-30: LGTM: Appropriate endpoint usage for VM operations

The write function correctly uses publish('vmaction', $message) which is appropriate for VM manager operations. This aligns with other VM scripts like VMAjaxCall.php and replaces the manual cURL implementation with the centralized publish function.

emhttp/plugins/dynamix.docker.manager/scripts/container_size (2)

17-17: LGTM: Clean integration of centralized publish function

The inclusion of publish.php is correctly placed and follows the established refactor pattern.


28-32: LGTM: Simplified and consistent message handling

The write function correctly delegates to publish('plugins', $message), removing the manual cURL setup and teardown while maintaining the same external interface. This aligns with the broader refactor to centralize message publishing across the Docker manager scripts.

emhttp/plugins/dynamix.docker.manager/scripts/update_container (2)

23-23: LGTM: Clean integration of centralized publish mechanism.

The inclusion of publish.php aligns with the broader refactor to standardize message dispatching across Dynamix plugin scripts.


36-36: LGTM: Simplified message publishing with better error handling.

The refactor from manual cURL management to the publish function provides several benefits:

  • Eliminates repetitive cURL setup/teardown code
  • Centralizes connection persistence and error handling
  • Automatic nginx restart handling on memory exhaustion
  • Consistent message publishing pattern across all Dynamix scripts
emhttp/plugins/dynamix.vm.manager/scripts/VMAjaxCall.php (2)

24-24: LGTM: Consistent adoption of centralized publishing.

Adding the publish.php include follows the established pattern across Dynamix VM manager scripts.


28-28: LGTM: Streamlined message publishing for VM operations.

The transition to publish('vmaction', $message) maintains consistency with other VM manager scripts (like VMClone.php) while leveraging the centralized error handling and connection management.

emhttp/plugins/dynamix.plugin.manager/scripts/language (2)

11-11: LGTM: Consistent publish integration across plugin manager scripts.

The inclusion of publish.php enables centralized message dispatching for language management operations.


74-74: LGTM: Proper conditional adoption of publish mechanism.

The refactor correctly maintains the conditional logic - using publish('plugins', $message) for web interface operations while preserving console output for direct script execution. The 'plugins' endpoint is appropriate for language management operations.

emhttp/plugins/dynamix/scripts/install_key (3)

14-14: LGTM: Improved robustness with proper docroot initialization.

The null coalescing assignment with fallback path ensures the script works reliably even when $_SERVER['DOCUMENT_ROOT'] is not available.


15-15: LGTM: Consistent publish mechanism integration.

Adding the publish.php include enables centralized message dispatching for license key operations.


19-19: LGTM: Streamlined message publishing for key installation.

The transition to publish('plugins', $message) provides consistent error handling and connection management while maintaining the same user-facing behavior.

emhttp/plugins/dynamix/scripts/ssd_trim (2)

32-32: LGTM: Consistent publish integration for system maintenance.

The inclusion of publish.php enables centralized message dispatching for SSD TRIM operations.


36-36: LGTM: Unified message publishing for TRIM operations.

The refactor to publish('plugins', $message) provides consistent progress reporting and error handling while maintaining all existing TRIM functionality for BTRFS, XFS, and ZFS filesystems.

emhttp/plugins/dynamix.plugin.manager/scripts/plugin (2)

11-11: LGTM: Clean inclusion of shared publish functionality.

The require_once statement correctly includes the shared publish.php file using the established $docroot variable pattern.


185-185: Excellent refactoring: Simplified message publishing.

Replacing the manual cURL implementation with the shared publish() function significantly improves code maintainability by:

  • Eliminating duplicate cURL boilerplate code
  • Centralizing publishing logic in a shared abstraction
  • Maintaining the same functional behavior with cleaner code

The 'plugins' channel name is appropriate for this context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor-nchan-publish

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ljm42 ljm42 added the 7.2 label Jul 24, 2025
@limetech limetech merged commit c1956f2 into master Jul 27, 2025
4 checks passed
@limetech limetech deleted the refactor-nchan-publish branch July 27, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants