Skip to content

251 memory reins#262

Open
cubap wants to merge 12 commits intomainfrom
251-memory-reins
Open

251 memory reins#262
cubap wants to merge 12 commits intomainfrom
251-memory-reins

Conversation

@cubap
Copy link
Copy Markdown
Member

@cubap cubap commented Apr 2, 2026

fixes #251

This pull request refactors several controller files to improve code maintainability and consistency. The main changes involve replacing manual object cloning with a utility function and standardizing pagination logic across multiple endpoints. These updates help reduce code duplication, make the codebase easier to maintain, and ensure more robust handling of request parameters.

Key changes include:

Object Cloning Consistency:

  • Replaced all instances of JSON.parse(JSON.stringify(...)) used for deep cloning objects with the centralized utils.cloneObject function in CRUD, patch, and update controller files. This change improves code clarity and avoids potential issues with JSON serialization. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18]

Pagination Handling Standardization:

  • Introduced and utilized a new getPagination utility function to extract limit and skip parameters with default values, replacing repeated manual parsing logic in CRUD, search, history, and Gallery of Glosses controller endpoints. This ensures consistent pagination behavior and reduces code duplication. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

Let me know if you have questions about how to use the new utility functions or why these refactors were made!

cubap added 4 commits April 2, 2026 15:24
Introduce cloneObject in utils.js that uses globalThis.structuredClone when available and falls back to JSON.parse(JSON.stringify(...)). Replace direct JSON cloning in configureRerumOptions for configuredObject and received_options with cloneObject, and export cloneObject. This centralizes cloning logic and allows better deep-clone behavior when structuredClone is supported.
Introduce MAX_QUERY_LIMIT and MAX_QUERY_SKIP and add clampNonNegativeInt and getPagination to safely parse and clamp limit/skip query params (with sensible defaults and env overrides). Replace ad-hoc deep copies (JSON.parse(JSON.stringify(...))) with utils.cloneObject in idNegotiation and getAllVersions to avoid issues with prototype loss and improve clarity. Export getPagination for reuse.
Replace repeated JSON.parse(JSON.stringify(...)) deep-clones with utils.cloneObject across controllers (crud, patchSet, patchUnset, patchUpdate, putUpdate, gog) and add/get getPagination to standardize parsing of limit/skip in search, gog and crud. Adjust imports accordingly to centralize cloning and pagination logic, improving readability and consistency.
@cubap cubap requested a review from thehabes as a code owner April 2, 2026 20:53
thehabes

This comment was marked as outdated.

cubap added 5 commits May 6, 2026 11:12
Replace numerous JSON.parse(JSON.stringify(...)) and utils.cloneObject calls with native structuredClone across controllers and utils for safer, more reliable deep copies. Remove the now-unused cloneObject helper from utils.js and update configureRerumOptions to use structuredClone. Also tweak clampNonNegativeInt to treat non-positive values (<= 0) as fallback, switch history HEAD handling to res.status(200).end(), and add safeBody usage in delete to avoid re-parsing request body.
Replace many end-to-end route tests with it.todo placeholders to temporarily stub numerous route test cases (files under routes/__tests__ and __tests__/routes_mounted.test.js). Update routes_mounted.test.js to safely access Express router stack via app._router?.stack ?? [] for compatibility. Resolve a merge/conflict in controllers/delete.js by removing logic that attempted to read an id from the request body and enforce that DELETE requires the id in the URL (returns a 400 if missing).
@thehabes thehabes self-requested a review May 6, 2026 18:46
cubap added 2 commits May 6, 2026 15:40
Replace placeholder todos with active integration tests that probe mounted routes via supertest. Removed the unused api_routes import and the routeExists helper; tests now perform actual HTTP requests against app for top-level paths (/v1, /client/register, /v1/id/:id, /v1/since/:id, /v1/history/:id) and for /v1/api/* endpoints using appropriate methods and content types, asserting endpoints are mounted (not 404) or return expected 404 for unknown IDs. This validates routing mounts across multiple HTTP verbs instead of relying on stack inspection.
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.

RERUM memory grows unbounded

2 participants