Skip to content

Conversation

@petruki
Copy link
Member

@petruki petruki commented Sep 1, 2025

This pull request refactors the cache worker management system to simplify event handling and improve test coverage. The main changes include replacing setter methods for event handlers with a constructor-based approach, cleaning up redundant error handling, and updating related tests and service functions.

Cache Worker Manager Refactor:

  • Replaced individual setter methods for event handlers (setOnCacheUpdates, setOnCacheDeletions, etc.) in CacheWorkerManager with a single constructor parameter that takes all event handlers as an object, simplifying initialization and usage. (src/helpers/cache/worker-manager.js, src/helpers/cache/index.js) [1] [2] [3] [4]
  • Removed redundant checks for handler existence before invocation, since all handlers are now required at construction. (src/helpers/cache/worker-manager.js)
  • Simplified error handling in the worker manager by removing unnecessary error event logic and redundant promise rejection. (src/helpers/cache/worker-manager.js)
  • Adjusted the worker manager's status update logic in the stop method for clarity. (src/helpers/cache/worker-manager.js)

Domain Service and Worker Updates:

  • Updated getAllDomains in domain.js to accept a select parameter for more efficient queries, and applied this in the worker to only fetch the lastUpdate field when refreshing the cache. (src/services/domain.js, src/helpers/cache/worker.js) [1] [2]
  • Cleaned up error handling in checkForDeletions by removing unnecessary try/catch blocks. (src/helpers/cache/worker.js) [1] [2]

Testing Improvements:

  • Added a new unit test file worker-manager.test.js to test the lifecycle and error handling of CacheWorkerManager. (tests/unit-test/cache/worker-manager.test.js)
  • Renamed and updated the cache tests to use consistent import paths and suite names, improving clarity and maintainability. (tests/unit-test/cache/cache.test.js) [1] [2] [3] [4] [5] [6]

@petruki petruki added this to the v1.1.0 milestone Sep 1, 2025
@petruki petruki self-assigned this Sep 1, 2025
@sonarqubecloud
Copy link

sonarqubecloud bot commented Sep 1, 2025

@petruki petruki merged commit 1ae3eb3 into master Sep 1, 2025
5 checks passed
@petruki petruki deleted the staging branch September 1, 2025 21:30
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.

2 participants