Blitzapps / blitz-orm

GNU Affero General Public License v3.0
23 stars 9 forks source link

feat:surrealDB queries 39-23 #66

Closed lveillard closed 5 months ago

sweep-ai[bot] commented 5 months ago

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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-818a8c85dc47caf05565427794e9d8643563595d712055d96a345275468f417eR16-R19)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-2a3b095f816d84f30d2b6a16c7f99518654a8a7c6141be4db400fadad2754085R305-R308)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-b28ebc9c06751024e4f15ac20c7de43c16a27c9ce5fe1b561d4e77e5d5adef6dR295-R315)
  • 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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-b28ebc9c06751024e4f15ac20c7de43c16a27c9ce5fe1b561d4e77e5d5adef6dR327-R336)
  • 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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-b28ebc9c06751024e4f15ac20c7de43c16a27c9ce5fe1b561d4e77e5d5adef6dR295-R315)
  • 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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-b28ebc9c06751024e4f15ac20c7de43c16a27c9ce5fe1b561d4e77e5d5adef6dR318-R324)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-d853d7c9cb0ddd81483e29161a4930069c8165232b130a7fec2016e2a3a0a8fbR118-R120)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-9708b91bca65d290a5a76dcabb939dc24b52f4c4ced89ea8fe67955379620a15R6-R24)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-3f740e3189dead1442784d27dbaad632c0bd1bb81baeef26075b456ec334eb3dR1-R29)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-375722f32bf8e9bf28781fab25bbdc240a584c62960d194434397193a329ab42R2-R4)

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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-2a3b095f816d84f30d2b6a16c7f99518654a8a7c6141be4db400fadad2754085R75-R77)
  • 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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-2a3b095f816d84f30d2b6a16c7f99518654a8a7c6141be4db400fadad2754085R75-R77)
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](https://github.com/Blitzapps/blitz-orm/pull/66/files#diff-17b787f4046846df90e02b2685e484cca60bb77f7d7e81ff2f3ea4181c0eb3d8R2-R4)

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.

lveillard commented 5 months ago

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.

sweep-ai[bot] commented 5 months ago

❌ 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.

lveillard commented 5 months ago

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

sweep-ai[bot] commented 5 months ago

❌ 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.