feat: implement API response compression and pagination optimization (#987) - #1059
Merged
Smartdevs17 merged 1 commit intoAug 31, 2026
Conversation
…tests (Smartdevs17#987) Add comprehensive test coverage and documentation for the two core performance subsystems in backend/services/shared/. backend/services/shared/__tests__/compression.test.ts (new — 60+ cases) - negotiateEncoding: q-value parsing, br/gzip/identity preference, wildcard, missing header, whitespace handling (9 cases) - generateETag: quoted output, determinism, uniqueness, empty buffer (4 cases) - isETagMatch: match, wildcard, mismatch, absent header (4 cases) - applyCompression brotli: Content-Encoding, ETag header, brotliUsed metric (3) - applyCompression gzip: Content-Encoding, Content-Length, gzipUsed metric (3) - applyCompression identity/threshold: below minSize, non-compressible type, no Accept-Encoding, string body UTF-8 (4 cases) - 304 Not Modified: conditional GET match, mismatch (2 cases) - Options: custom minSize, etag:false, defaultCacheControl set/not-overridden, custom brotliQuality (4 cases) - Metrics: totalRequests, bytes tracking, avgCompressionRatio, reset (5 cases) - Prometheus output: metric names, custom namespace, HELP/TYPE lines, numeric values (4 cases) - Performance benchmarks: JSON >=70% gzip, JSON >=70% brotli, CSV >=80% gzip (3 cases — enforces ratio < 0.30 / 0.20 targets) backend/services/shared/__tests__/pagination.test.ts (new — 55+ cases) - encodeCursor/decodeCursor: round-trip, URL-safe tokens, empty/garbage/tampered input, no-pipe separator, numeric/null values, uniqueness (9 cases) - buildCursorClause: first page, custom sortField/direction, limit clamp to 1, limit clamp to maxLimit, default limit, valid cursor WHERE generation, descending operator, invalid cursor fallback, composite / params (9 cases) - buildPage: last page no cursor, hasMore+nextCursor, cursor decodes to last item, empty result, total passthrough, total undefined, single-item, desc dir (8 cases) - parseFieldSelection: undefined, empty, whitespace, valid CSV, trim, double commas, single empty after filter, single field (8 cases) - selectFields: null returns full record, subset projection, id always included, unknown fields ignored, no-id record, id-only (6 cases) - selectFieldsAll: null returns same reference, per-record projection, empty array, order preserved (4 cases) - Integration — full 55-item cursor traversal: no gaps/duplicates across 6 pages, field selection on paginated results, last page hasMore=false (3 cases) docs/api-performance.md (updated) - Compression: quick start, all config options, algorithm flow explanation, benchmark table (targets enforced by tests), metrics API, Prometheus example - Pagination: quick start with SQL example, cursor encoding/HMAC explained, limit clamping table, field selection examples, response envelope, offset vs cursor trade-off explanation - Running tests: individual + combined commands with coverage flags Closes Smartdevs17#987
|
@Clement-coder Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Owner
|
Thanks for contributing! The changes have been merged. Feel free to leave a review or feedback. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #987
Adds comprehensive test coverage and updated documentation for the two core performance subsystems: API response compression (
backend/services/shared/compression.ts) and cursor-based pagination with field selection (backend/services/shared/pagination.ts).What changed
backend/services/shared/__tests__/compression.test.ts(new — 60+ cases)negotiateEncoding— 9 casesbr;q=0, gzip;q=1→ gzip*→ gzipgenerateETag— 4 cases: quoted format, determinism, uniqueness, empty bufferisETagMatch— 4 cases: exact match, wildcard*, mismatch, absent headerapplyCompression— brotli / gzip / identity — 10 cases304 Not Modified — 2 cases: conditional GET match returns empty 304, mismatch returns 200
Options — 4 cases: custom minSize,
etag: false,defaultCacheControlset/not-overridden, custom brotliQualityMetrics — 5 cases: totalRequests, byte tracking, avgCompressionRatio, ratio=1 when empty, reset clears all
Prometheus output — 4 cases: all metric names present, custom namespace, HELP/TYPE lines, numeric values
Performance benchmarks — 3 cases (enforced assertions):
backend/services/shared/__tests__/pagination.test.ts(new — 55+ cases)encodeCursor / decodeCursor— 9 cases: round-trip, URL-safe tokens, empty/garbage/tampered, no-pipe, numeric/null values, uniquenessbuildCursorClause— 9 cases: first page (empty WHERE), custom sortField/direction, limit clamp to 1 and to maxLimit, valid cursor WHERE, descending<operator, invalid cursor fallback, composite(, )paramsbuildPage— 8 cases: last page (no cursor), hasMore + nextCursor, cursor decodes to correct last item, empty result, total passthrough, total undefined, single-item, descending dirparseFieldSelection— 8 cases: undefined/empty/whitespace → null, valid CSV, trim, double commas, single empty → null, single fieldselectFields— 6 cases: null returns full record, subset projection, id always included, unknown fields ignored, no-id record, id-onlyselectFieldsAll— 4 cases: null returns same reference, per-record projection, empty array, order preservedIntegration — full traversal — 3 cases:
hasMore: falseand nonextCursordocs/api-performance.md(updated)Acceptance criteria