Skip to content

fix: remove unused SurrealDB scripting feature (~10-20MB savings)#3

Closed
HexaField wants to merge 2 commits into
devfrom
fix/remove-surrealdb-scripting
Closed

fix: remove unused SurrealDB scripting feature (~10-20MB savings)#3
HexaField wants to merge 2 commits into
devfrom
fix/remove-surrealdb-scripting

Conversation

@HexaField
Copy link
Copy Markdown
Owner

Summary

Removes the SurrealDB scripting feature, which embeds a full QuickJS JavaScript engine inside SurrealDB. This engine is defined in the schema but never called by production code — all fn:: references exist only in #[cfg(test)] blocks.

Expected savings

  • ~10-20MB RSS (QuickJS runtime + heap, even when idle)
  • ~2-5MB binary size (QuickJS engine code)
  • 96 lines removed from Cargo.lock (rquickjs, rquickjs-core, rquickjs-sys, bindgen, and transitive deps)

What changed

Before (JS-scripted) After (pure SurrealQL)
fn::contains — inline JS str.includes() string::contains() native wrapper
fn::regex_match — inline JS RegExp.test() string::matches() native wrapper
fn::parse_literal — JS with decodeURIComponent + JSON.parse Pure SurrealQL with fn::url_decode helper. Supports string:, number:, boolean: prefixes. json: case removed (requires JS engine).
fn::strip_html — JS regex replace Removed — no regex replace in SurrealQL, no production callers
fn::json_path — JS dynamic object traversal Removed — no dynamic path traversal in SurrealQL, no production callers

New: fn::url_decode helper

A pure SurrealQL function that decodes common percent-encoded characters (%20 → space, %22 → double-quote, %3A → colon, etc.) using a chain of string::replace calls. Handles the 22 most common URL-encoded characters. Used by fn::parse_literal for the string: prefix.

Risk: Low

  • Zero production queries call these functions
  • All affected tests updated to work with the pure SurrealQL implementations
  • literal://json: test updated to expect passthrough behavior (raw URL returned)

Note

cargo check cannot be verified locally due to a pre-existing xcodebuild/v8 toolchain issue (Xcode not installed, only Command Line Tools). CI will validate.

Remove the SurrealDB `scripting` feature which embeds a QuickJS JavaScript
engine. This saves ~10-20MB RSS and ~2-5MB binary size.

Changes:
- Remove `scripting` from surrealdb features in Cargo.toml
- Remove `.with_scripting(true)` capability configuration
- Rewrite fn::contains and fn::regex_match as thin wrappers around native
  SurrealQL functions (string::contains, string::matches)
- Rewrite fn::parse_literal in pure SurrealQL with a fn::url_decode helper
  for percent-decoding (supports string:, number:, boolean: prefixes)
- Remove fn::strip_html (requires regex replace, unavailable in pure SurrealQL)
- Remove fn::json_path (requires dynamic object traversal, unavailable in SurrealQL)
- Add fn::url_decode helper for common percent-encoded characters

Zero production queries call any of these functions — all 29 fn:: references
are inside #[cfg(test)] blocks. The literal://json: case (which required
JSON.parse via QuickJS) is dropped; json: literals pass through as raw URLs.
Tests updated accordingly.
@HexaField HexaField closed this Feb 20, 2026
@HexaField HexaField deleted the fix/remove-surrealdb-scripting branch February 21, 2026 00:38
HexaField pushed a commit that referenced this pull request Feb 23, 2026
…#652)

* Surreal files per perspective wip 1

* Avoid duplicate links w/ unique index and handle lock and write errors

* Fix new remove_link on surreal service

* Rename update_surreal_cache() to persist_link_diff()

* Temporary perspective data migration from rusqlite to surreal

* fmt

* fix: address CodeRabbit issues #2, #3, coasys#7

- MIGRATION_REMOVAL_GUIDE.md: Complete sentence in heading
- migration.rs: Only mark as migrated when error_count == 0 (prevents data loss)
- surreal_service/mod.rs: Remove overly broad 'index' error check (more precise error handling)

Addresses CodeRabbit actionable comments on PR coasys#652

* fix: preserve original link status instead of hardcoding Local (issue #4)

Instead of hardcoding LinkStatus::Local, now reads link.status and uses it
(falls back to Local if None). This preserves the original link status during
import operations.

Addresses CodeRabbit actionable comment on PR coasys#652

* fix: propagate SurrealDB write failures to prevent desync (issue #1)

- retry_surreal_op now returns Result and propagates errors
- persist_link_diff now returns Result instead of silently swallowing errors
- Updated all callsites:
  - Functions returning Result: use .await? to propagate
  - Functions returning (): use .await.expect() to fail-fast
- Critical synchronization operations now fail loudly instead of silently

Addresses CodeRabbit actionable comment #1 on PR coasys#652

* fix: honor full unique constraint in SurrealDB lookups (issue coasys#6)

Updated get_link to accept and use author and timestamp parameters:
- get_link now takes optional author and timestamp
- When provided, queries using all 5 unique fields (source, target, predicate, author, timestamp)
- When not provided, falls back to 3-field lookup for backward compatibility
- Updated all callsites to pass author and timestamp from LinkExpression

This prevents returning arbitrary links when multiple authors/timestamps exist
for the same source/predicate/target combination.

Addresses CodeRabbit actionable comment coasys#6 on PR coasys#652

* fix: prevent TOCTOU race in initialize_from_db (issue #5)

Added atomic check-and-insert before storing perspective:
- Initial read-lock check remains for quick filtering
- After async initialization completes, do final write-lock check
- Only insert if another task hasn't already initialized this perspective
- Discard duplicate work and don't start background tasks if race lost

This prevents multiple tasks from creating duplicate SurrealDB services
for the same perspective UUID.

Addresses CodeRabbit actionable comment #5 on PR coasys#652

* fix: clone link.status to avoid partial move

Compilation error: link.status.unwrap_or() moves the value, preventing
use of 'link' afterwards. Use clone() to avoid the partial move.

* fix: borrow links in migration loop to avoid partial move

Changed 'for (link_expr, status) in links' to '&links' and cloned status
to avoid moving values out of the vector.

* chore: run cargo fmt and add PR fixes summary

* refactor: remove redundant variable reassignments in get_link

Addresses CodeRabbit feedback: simplified variable flow by directly
assigning query result to response instead of going through intermediate
query and results variables.

Co-authored-by: CodeRabbit AI <coderabbit@example.com>

* fix: address CodeRabbit feedback on PR coasys#652

1. Remove 'WHERE perspective = $perspective' from test queries
   - Each perspective has isolated database, no filtering needed
   - Fixed 11 test queries in surreal_service/mod.rs

2. Make status parsing case-insensitive in SurrealLink conversion
   - Now handles 'Shared'/'shared' and 'Local'/'local' correctly
   - Preserves migrated data regardless of case

3. Require author/timestamp in get_link() signature
   - Changed from Option<&str> to &str for both params
   - Removed fallback branch (always use full unique constraint)
   - Updated 4 callsites in perspective_instance.rs
   - Enforces UNIQUE index (in, out, predicate, author, timestamp)

Co-authored-by: CodeRabbit AI <coderabbit@example.com>

* reset bootstrapSeed.json

* Handle fallback sync read failure gracefully.

* Don’t proceed when migration fails.

* Fix inconsistent error handling: .expect() vs. map_err()?

* fix: handle SurrealDB service creation failure in initialize_from_db

Complements commit e57b8f8 which fixed the same issue in add_perspective().
This fix addresses the spawned task in initialize_from_db() which also had
a panicking .expect() call.

Changes:
- Replace .expect() with match expression
- Log error and return early on failure
- Prevents panic if SurrealDB creation fails (RocksDB lock, disk, permissions)

Addresses CodeRabbit feedback on PR coasys#652 (line 90 issue)

* don't fail silently if links from DB can't be parsed

* don't panic on DB write failures but log error

---------

Co-authored-by: Data <data.coasys@gmail.com>
Co-authored-by: CodeRabbit AI <coderabbit@example.com>
lucksus pushed a commit that referenced this pull request Feb 26, 2026
- Use SHACLShape.toJSON() in ensureSDNASubjectClass instead of manual JSON (coasys#15)
- Refactor getSubjectClassMetadataFromSDNA to use getShacl()/SHACLShape.fromLinks() (coasys#14)
- Update addSdna docs to clarify SHACL is primary, Prolog kept for compat (#1)
- Mark Phase 3 as completed in architecture doc (#3)
- Add .worktrees/ to .gitignore
HexaField pushed a commit that referenced this pull request Mar 6, 2026
…rdcoding

Address review comments #3 and #4 from Nico:
- subscriptions.rs: When no explicit predicate is provided, load the
  SHACL class definition and derive the SurrealQL query from its
  property predicates (IN clause). No more hardcoded flux:// types.
- shacl.rs: Enrich ShaclClass with shape_uri and all_predicates fields,
  providing enough metadata to construct targeted queries without
  type-specific knowledge.
- Add load_class_properties_with_uri() to return shape URI alongside
  properties for richer metadata.
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