blitz-orm icon indicating copy to clipboard operation
blitz-orm copied to clipboard

feat:surrealDB queries 39-23

Open lveillard opened this issue 1 year ago • 1 comments

lveillard avatar May 23 '24 21:05 lveillard

Sweep: PR Review

This pull request enhances SurrealDB query handling and introduces benchmark testing.

The main change involved modifying how $filter mappings are processed. The $filterProcessed property was removed from various types and functions, and the mapFilterKeys function was relocated to be used exclusively within TQL (Typed Query Language) queries. This ensures that $filter mappings are now only applied in TQL contexts, simplifying the BQL (Basic Query Language) processing logic.

Additionally, a new benchmark test was added. The bench.sh script was created to automate the setup and teardown of a SurrealDB Docker container for running these benchmarks. This script initializes the database, imports schema and data, and executes the benchmarks using npx vitest bench.

Minor changes included updating test descriptions and filter conditions to improve clarity and accuracy. For example, test cases were renamed to better reflect their purpose, such as changing "ef6[entity,filter] - $filter by unique field" to "ef6[entity,filter,id] - $filter by id in filter".

The changelog was updated to reflect these changes, documenting the new version 0.10.13 and the addition of benchmark tests and SurrealDB query enhancements.


Sweep Found These Issues

src/adapters/surrealDB/types/base.ts
  • The removal of the $filterProcessed property may cause functional issues in parts of the codebase that rely on this property to determine the processing state of filters.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2Fadapters%2FsurrealDB%2Ftypes%2Fbase.ts#L16-L19 View Diff

src/stateMachine/query/bql/enrich.ts
  • Directly assigning field.$filter without transformation in createRoleField may lead to incorrect filter application if the schema requires key mapping.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Fbql%2Fenrich.ts#L305-L308 View Diff

src/stateMachine/query/tql/build.ts
  • The mapFilterKeys function does not handle cases where thingSchema is null or undefined, which could lead to runtime errors.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Ftql%2Fbuild.ts#L295-L315 View Diff

  • The buildFilter function now relies on mapFilterKeys, but there is no error handling if mapFilterKeys returns an invalid or unexpected filter structure.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Ftql%2Fbuild.ts#L327-L336 View Diff

  • Sweep has identified a redundant function: The new function mapFilterKeys is redundant as its functionality is already covered by processFilter and mapPositiveFilterKeys.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Ftql%2Fbuild.ts#L295-L315 View Diff

  • Sweep has identified a redundant function: The new function mapPositiveFilterKeys is redundant because its functionality is already covered by the existing mapFilterKeys function, which calls mapPositiveFilterKeys internally.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Ftql%2Fbuild.ts#L318-L324 View Diff

src/types/requests/queries.ts
  • The removal of the $filterProcessed property from the EnrichedRoleQuery type may break existing logic that relies on this property to determine the processing state of a filter.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2Ftypes%2Frequests%2Fqueries.ts#L118-L120 View Diff

tests/bench.sh
  • The script does not handle potential errors from Docker commands, which could lead to silent failures or incomplete setups.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/tests%2Fbench.sh#L6-L24 View Diff

tests/surrealdb/README.md
  • The removal of tests/surrealdb/README.md eliminates critical setup and testing instructions, which could hinder developers from properly setting up and running tests for SurrealDB.
  • https://github.com/Blitzapps/blitz-orm/blob/46a669171ae95cafbe31d77d13b5278c0cbc23cd/tests%2Fsurrealdb%2FREADME.md#L1-L29 View Diff

tests/surrealdb/bench/all.bench.ts
  • The init function is used without any error handling, which could lead to unhandled exceptions if init fails.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/tests%2Fsurrealdb%2Fbench%2Fall.bench.ts#L2-L4 View Diff


Potential Issues

Sweep is unsure if these are issues, but they might be worth checking out.

src/stateMachine/query/bql/enrich.ts
  • The removal of the mapFilterKeys function means that filter keys will no longer be transformed based on the schema, which could lead to incorrect filter processing if the schema paths differ from the database paths.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Fbql%2Fenrich.ts#L75-L77 View Diff

  • The removal of the mapFilterKeys function and its associated logic means that filters will no longer be transformed based on the schema, which could lead to incorrect filter processing.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/src%2FstateMachine%2Fquery%2Fbql%2Fenrich.ts#L75-L77 View Diff

tests/typedb/bench/all.bench.ts
  • The init function is called within the benchmark test without any error handling, which could cause the benchmark to fail if init throws an error.
  • https://github.com/Blitzapps/blitz-orm/blob/1f80eb4b08d800b38c54658d1918d579c6c5210d/tests%2Ftypedb%2Fbench%2Fall.bench.ts#L2-L4 View Diff


package.json was not reviewed because our filter identified it as typically a non-human-readable or less important file (e.g., dist files, package.json, images). If this is an error, please let us know.

Sweep: Please fix these:

File: tests/bench.sh The script does not handle potential errors from Docker commands, which could lead to silent failures or incomplete setups.

File: tests/surrealdb/bench/all.bench.ts The init function is used without any error handling, which could lead to unhandled exceptions if init fails.

lveillard avatar May 29 '24 16:05 lveillard

❌ An error occured!

The exception message is:/tmp/cache/repos/Blitzapps/blitz-orm/b4e33ac3c01cd732fc6f5e85ce06c9d85d6107d5b027f9bd249c8c36a2adcc39/feat-surrealdb-queries/tests/surrealdb/README.md does not exist.

The stack trace is:Traceback (most recent call last): File "/app/sweepai/handlers/on_comment.py", line 277, in on_comment snippets_modified = [Snippet.from_file( File "/app/sweepai/handlers/on_comment.py", line 278, in pr_diff.file_name, cloned_repo.get_file_contents(pr_diff.file_name) File "/app/sweepai/utils/github_utils.py", line 501, in get_file_contents raise FileNotFoundError(f"{local_path} does not exist.") FileNotFoundError: /tmp/cache/repos/Blitzapps/blitz-orm/b4e33ac3c01cd732fc6f5e85ce06c9d85d6107d5b027f9bd249c8c36a2adcc39/feat-surrealdb-queries/tests/surrealdb/README.md does not exist.

Please report this on our community forum.

This is an automated message generated by Sweep AI.

Sweep: Please fix these:

File: tests/bench.sh The script does not handle potential errors from Docker commands, which could lead to silent failures or incomplete setups.

File: tests/surrealdb/bench/all.bench.ts The init function is used without any error handling, which could lead to unhandled exceptions if init fails.

Dont explore this file, as it was deleted in this PR, so please dont review it: /tests/surrealdb/README.md

lveillard avatar May 29 '24 16:05 lveillard

❌ An error occured!

The exception message is:/tmp/cache/repos/Blitzapps/blitz-orm/617a5e3467d60497fb4105c52b112ca8c9cae585007af96beb9801214aaf4f74/feat-surrealdb-queries/tests/surrealdb/README.md does not exist.

The stack trace is:Traceback (most recent call last): File "/app/sweepai/handlers/on_comment.py", line 277, in on_comment snippets_modified = [Snippet.from_file( File "/app/sweepai/handlers/on_comment.py", line 278, in pr_diff.file_name, cloned_repo.get_file_contents(pr_diff.file_name) File "/app/sweepai/utils/github_utils.py", line 501, in get_file_contents raise FileNotFoundError(f"{local_path} does not exist.") FileNotFoundError: /tmp/cache/repos/Blitzapps/blitz-orm/617a5e3467d60497fb4105c52b112ca8c9cae585007af96beb9801214aaf4f74/feat-surrealdb-queries/tests/surrealdb/README.md does not exist.

Please report this on our community forum.

This is an automated message generated by Sweep AI.