Skip to content

feat: avoid unnecessary stat on every save - #101

Closed
avoidwork wants to merge 0 commit into
mainfrom
feat/avoid-unnecessary-mkdir
Closed

feat: avoid unnecessary stat on every save#101
avoidwork wants to merge 0 commit into
mainfrom
feat/avoid-unnecessary-mkdir

Conversation

@avoidwork

Copy link
Copy Markdown
Owner

Description

saveSession() was calling stat() + mkdir() on every save call. Since every message triggers a save, this means redundant filesystem checks and directory creation fire N times during a session.

This changes saveSession() to a pure writeFile — the directory is ensured once at init via ensureSessionsDir(). If the directory disappears after init, saves fail (crash) instead of silently creating it.

This is an optimization over the existing behavior from #99 — the directory existence guarantee was already in the design, but mkdir was still happening on every save.

Type of Change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactor (no functional change)
  • Performance improvement
  • CI / build / tooling

Testing

Full test suite: 955/955 tests pass. New tests added:

  • saver.test.js: saveSession writes file with correct content; defaults filename to unsaved.md
  • saver_errors.test.js: saveSession propagates writeFile errors unhandled
  • session.test.js: ensureSessionsDir creates directory when missing; returns when directory exists
  • shutdown.test.js: handleShutdown re-throws saveSession errors; suppresses telemetry flush errors; calls onShutdown callback; executes saveSession after flushTelemetry

Coverage

  • 100% line coverage maintained

Checklist

  • npm run lint passes
  • Tests pass with 100% line coverage
  • No forbidden patterns used
  • Conventional Commit style applied

@avoidwork avoidwork changed the title feat: avoid unnecessary mkdir on every save by ensuring dir at init feat: avoid unnecessary stat on every save Jun 4, 2026
@avoidwork avoidwork closed this Jun 4, 2026
@avoidwork
avoidwork force-pushed the feat/avoid-unnecessary-mkdir branch from b347e06 to 3ae3bc6 Compare June 4, 2026 22:14
@avoidwork
avoidwork deleted the feat/avoid-unnecessary-mkdir branch June 4, 2026 22:17
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