Skip to content

Conversation

@lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Nov 19, 2025

STATUS: DRAFT / WORK IN PROGRESS - Does not compile yet

This PR refactors the request handling to separate immutable request data from mutable execution state, avoiding unnecessary cloning of potentially large data structures.

Problem

Currently, run_sql() clones the entire RequestInfo which includes:

  • All HTTP headers
  • All cookies
  • Request body
  • URL parameters
  • POST parameters
  • Uploaded file references

This is wasteful since only set_variables and clone_depth need to be cloned.

Solution

Split into two structures:

  • RequestInfo: immutable request data (wrapped in Rc)
  • ExecutionContext: mutable execution state + reference to RequestInfo

Benefits

  • Avoid cloning large strings in nested run_sql() calls
  • Clearer separation of concerns
  • Better performance for recursive SQL includes

Status

  • Define new structures
  • Update all function signatures (~50+ functions)
  • Update execute_queries.rs
  • Update syntax_tree.rs
  • Update sqlpage_functions
  • Tests passing

Based on: #1109

- URL and POST parameters are now immutable after request initialization
- SET command creates user-defined variables in separate namespace
- Variable lookup: SET variables shadow request parameters
- Added sqlpage.variables('set') to inspect user-defined variables
- Simplified API: most functions now use &RequestInfo instead of &mut
- All tests passing (151 total)
- Warn when both URL and POST have same variable name
- Warn when $var is used for POST-only variable (should use :var)
No need to branch on whether variables are provided since we clone in both cases anyway.
This is a draft refactoring to avoid cloning large immutable data (headers,
cookies, body) when creating nested execution contexts in run_sql().

Changes:
- RequestInfo now contains only immutable request data
- ExecutionContext wraps Rc<RequestInfo> + mutable execution state
- Avoids cloning potentially large strings in nested run_sql() calls

Status: NOT COMPILING YET - this is work in progress
Base automatically changed from immutable-url-params to main November 19, 2025 02:10
@lovasoa lovasoa closed this Nov 19, 2025
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