Skip to content

Comments

feat: add compression middleware and optimize serial port loading#4501

Merged
robertsLando merged 5 commits intozwave-js:masterfrom
zackbcom:compress
Feb 19, 2026
Merged

feat: add compression middleware and optimize serial port loading#4501
robertsLando merged 5 commits intozwave-js:masterfrom
zackbcom:compress

Conversation

@zackbcom
Copy link
Contributor

@zackbcom zackbcom commented Dec 22, 2025

It is currently taking 1 second plus to load the serial ports for me. (Docker container) Adding compression only sped it up a little, but the payload is much smaller now (compressed). Moved pulling serial to the settings page where it's only used.
If you don't want a breaking change on the api, could add a param to the api to exclude pulling serial.

This pull request improves the performance and maintainability of the API and frontend by introducing response compression and refactoring how serial port information is loaded. The serial ports are now fetched via a separate API endpoint, allowing the settings page to load faster without waiting for potentially slow serial port enumeration. Additionally, response compression is enabled to reduce bandwidth usage.

API Improvements:

  • Added the compression middleware to the Express app to compress all HTTP responses larger than 1KB, improving network efficiency. (api/app.ts, package.json) [1] [2] [3]
  • Refactored the /api/settings endpoint to remove serial port enumeration, making it faster and more reliable. (api/app.ts) [1] [2]
  • Introduced a new /api/serial-ports endpoint that asynchronously enumerates serial ports, returning results separately from settings. (api/app.ts)

Frontend Improvements:

  • Updated the ConfigApis module to add a getSerialPorts method for fetching serial port data from the new endpoint. (src/apis/ConfigApis.js)
  • Changed the settings page logic to load serial ports separately after the main settings load, improving perceived performance and user experience. (src/views/Settings.vue, src/stores/base.js) [1] [2]Introduce compression middleware to enhance response optimization and load serial ports separately in the settings view to improve performance. This change ensures that the settings page remains responsive while fetching serial port data.

Screenshots

  • Validation Scripts
    • Before Code Change
      • Screenshot 2025-12-22 at 1 18 00 AM
    • After Code Change
      • Screenshot 2025-12-22 at 1 18 16 AM
    • New Endpoint timings
      • Screenshot 2025-12-22 at 1 38 38 AM
  • Before
    • Screenshot 2025-12-22 at 3 18 27 AM
  • After
    • Screenshot 2025-12-22 at 3 21 16 AM
  • After (settings Page extra call)
    • Screenshot 2025-12-22 at 3 22 16 AM

@coveralls
Copy link

Pull Request Test Coverage Report for Build 20427107452

Details

  • 0 of 70 (0.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.02%) to 19.513%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/apis/ConfigApis.js 0 4 0.0%
src/stores/base.js 0 4 0.0%
api/app.ts 0 62 0.0%
Totals Coverage Status
Change from base Build 20394770530: -0.02%
Covered Lines: 4052
Relevant Lines: 22034

💛 - Coveralls

@zackbcom zackbcom changed the title Add compression middleware and optimize serial port loading Fix: Add compression middleware and optimize serial port loading Dec 22, 2025
@zackbcom zackbcom changed the title Fix: Add compression middleware and optimize serial port loading feat: Add compression middleware and optimize serial port loading Dec 22, 2025
@zackbcom zackbcom changed the title feat: Add compression middleware and optimize serial port loading feat: add compression middleware and optimize serial port loading Dec 22, 2025
@robertsLando robertsLando requested a review from Copilot February 19, 2026 09:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves perceived performance of the Settings UI and reduces response payload sizes by enabling HTTP response compression and moving serial port enumeration out of the /api/settings payload into a dedicated endpoint.

Changes:

  • Add Express compression middleware (threshold 1KB) to compress API/static responses.
  • Refactor /api/settings to no longer enumerate serial ports; introduce /api/serial-ports for on-demand enumeration.
  • Update Settings view and client API wrapper to fetch serial ports separately and initialize them in the base store.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
api/app.ts Adds compression middleware; removes serial port enumeration from /api/settings; adds /api/serial-ports endpoint.
src/views/Settings.vue Loads settings first, then triggers a separate serial ports fetch without blocking the settings UI.
src/stores/base.js Makes serial_ports initialization conditional since /api/settings no longer always includes it.
src/apis/ConfigApis.js Adds getSerialPorts() client method calling the new endpoint.
package.json Adds compression dependency.
package-lock.json Updates lockfile for the new dependency (plus additional metadata churn).

Integrate master's managedExternally settings and ZWAVE_PORT check
into the compress branch's separated serial-ports endpoint.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@robertsLando
Copy link
Member

@zackbcom I'm so sorry I have missed your PR, too many notifications when I came back from Christmas 😢

I'm fixing some things locally, thanks a lot for this improvement 🙏🏼

robertsLando and others added 2 commits February 19, 2026 10:36
Add return in serial-ports catch block to prevent double response,
and add @types/compression dev dependency for proper TS types.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@robertsLando robertsLando merged commit 9ad02f7 into zwave-js:master Feb 19, 2026
12 checks passed
@zackbcom
Copy link
Contributor Author

Thank you! settings are so much snappier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants