Skip to content

fix: review findings + cache/quota performance refinements (v1.3.1)#3

Merged
chenliuyun merged 1 commit into
mainfrom
fix/review-and-perf
Apr 19, 2026
Merged

fix: review findings + cache/quota performance refinements (v1.3.1)#3
chenliuyun merged 1 commit into
mainfrom
fix/review-and-perf

Conversation

@chenliuyun

Copy link
Copy Markdown
Collaborator

Summary

  • Post-v1.3.0 review fixes: name-resolver drops reverse substring match; expand requires cached device for setPosition and restricts setMode to Relay Switch; device-meta validates schema version and writes atomically; plan JSON Schema enforces deviceId/deviceName mutual exclusion.
  • Cache/quota refinements: getCachedTypeMap() lets batch/watch skip the device-list round-trip when --ids is supplied; status cache gains a hot-cache (with a test reset); batch/watch reuse one axios client; quota writes are debounced (250ms) with flush hooks; SIGINT/SIGTERM now exit 130/143 after flushing.
  • Version bump to 1.3.1 with package-lock.json resynced.

Test plan

  • npm run build clean
  • npm test — 658/658 pass across 36 files
  • Smoke: switchbot devices batch turnOff --ids ID1,ID2 --dry-run issues no GET /v1.1/devices
  • Smoke: switchbot quota status shows counts after a burst of calls and after a SIGINT

Review fixes (on top of v1.3.0):
- name-resolver: drop reverse substring match (q.includes(name)) to avoid
  long queries collapsing onto short device names
- expand: require cached device for setPosition so Curtain vs Blind Tilt
  dispatch is reliable; tighten setMode to Relay Switch* only; use
  startsWith for Blind Tilt to tolerate future variants
- device-meta: validate version === '1' on load; atomic tmp+rename writes
- plan: JSON Schema enforces deviceId/deviceName mutual exclusion,
  aligning with runtime validatePlan() behavior

Cache/quota refinements:
- cache: getCachedTypeMap() lets batch/watch skip the unnecessary
  GET /v1.1/devices when --ids already names the targets
- cache: hot-cache for status cache (resetStatusCache for tests)
- batch/watch: reuse a single axios client across a run
- quota: debounced writes (250ms) + flush hooks on beforeExit/exit;
  SIGINT/SIGTERM handlers now exit with 130/143 after flushing
- lib/devices: plumb ttlMs from read mode into setCachedStatus

Tests updated for the new reset/flush hooks; 658/658 pass.
@chenliuyun chenliuyun merged commit e006235 into main Apr 19, 2026
3 checks passed
@chenliuyun chenliuyun deleted the fix/review-and-perf branch April 19, 2026 02: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.

1 participant