-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: where type issues #958
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe pull request introduces changes in two files: Changes
Sequence DiagramsequenceDiagram
participant LD as listDuplicates
participant LDE as listDuplicatesEnhanced
participant TG as TypeGraphDS
LD->>LDE: Call with TypeGraph
LDE->>TG: Analyze Type Graph
LDE-->>LDE: Detect Duplicates
LDE-->>LDE: Build Reduced Set Map
LDE->>LDE: Process Type Relationships
LDE-->>LD: Return Duplicate Information
The sequence diagram illustrates the new flow where Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (2)
tools/list-duplicates.ts (2)
29-30
: Remove unused variable 'theWheres' or uncomment the code that uses itThe variable
theWheres
is populated but not utilized since the code that uses it (lines 248-253) is commented out. This may cause confusion and unnecessary memory usage.Consider either removing the unused variable and related code if it's no longer needed, or uncommenting and updating the code block to utilize
theWheres
appropriately.Also applies to: 248-253
124-142
: Clean up commented-out code in 'suffix2' generationIn the
name
method, there is a block of commented-out code regardingnested_suffix
and processing of keys (lines 124-142). Keeping unused code can reduce readability and maintainability.Consider removing the commented-out code to clean up the method:
let suffix2 = if !self.skip_models.is_empty() { - /* let nested_suffix = if self.aggregates { - "_where_with_aggregates" - } else { - "_where" - }; */ let mut keys = self .skip_models .keys() .cloned() .collect::<Vec<_>>(); keys.sort(); format!("_excluding_{}", keys.join("_and_")) } else { "".to_string() };
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (20)
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__query_where_expr__tests__Post__QueryWhereExpr.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__query_where_expr__tests__User__QueryWhereExpr.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many Post out.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_many User out.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique Post inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique Post out.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique User inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__find_unique User out.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by Post out.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__group_by User out.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_many Post inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_many User inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_one Post inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__test__update_one User inp.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__where___test__where Post.snap
is excluded by!**/*.snap
src/typegraph/core/src/runtimes/prisma/type_generation/snapshots/typegraph_core__runtimes__prisma__type_generation__where___test__where User.snap
is excluded by!**/*.snap
📒 Files selected for processing (2)
src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs
(4 hunks)tools/list-duplicates.ts
(3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
- GitHub Check: lint-compat (macos-14, aarch64-apple-darwin, false)
- GitHub Check: lint-compat (macos-13, x86_64-apple-darwin, false)
- GitHub Check: test-full
- GitHub Check: pre-commit
🔇 Additional comments (2)
src/typegraph/core/src/runtimes/prisma/type_generation/where_.rs (2)
20-20
: Assess the impact of changing 'skip_models' key from 'TypeId' to 'String'Changing the key type of
skip_models
fromTypeId
toString
(line 20) may have performance implications due to the costlier string comparisons and potential for key collisions if different models share the same name. In line 64, when accessingskip_models
, ensure that the model names are unique and consistent.Please confirm that model names are unique identifiers in this context and that this change won't introduce unintended side effects. If necessary, consider using a combination of
TypeId
andString
or another unique identifier to maintain performance and correctness.Also applies to: 64-64
Line range hint
78-83
: Ensure 'edges' correctly accumulates dependencies in 'function' caseSimilar to the issue in
listDuplicatesEnhanced
, verify that in thegenerate
method, when constructingedges
, the dependencies for 'function' types include bothinput
andoutput
without overwriting. This ensures proper traversal and processing of type relations.Review the logic around building
edges
to confirm that bothinput
andoutput
dependencies are accounted for correctly.
edges.set(idx, [structure.input]); | ||
addToRevEdges(structure.input, idx); | ||
edges.set(idx, [structure.output]); | ||
addToRevEdges(structure.output, idx); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix overwriting of edges in 'function' case to include both input and output edges
In the 'function' case of the switch statement, the code calls edges.set(idx, ...)
twice, which overwrites the previous value. As a result, only the last edge is stored, and the input edge is lost. This can lead to incorrect graph traversal or incomplete processing of types.
Apply this diff to fix the issue:
case "function":
- edges.set(idx, [structure.input]);
- addToRevEdges(structure.input, idx);
- edges.set(idx, [structure.output]);
+ edges.set(idx, [structure.input, structure.output]);
addToRevEdges(structure.input, idx);
addToRevEdges(structure.output, idx);
break;
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
edges.set(idx, [structure.input]); | |
addToRevEdges(structure.input, idx); | |
edges.set(idx, [structure.output]); | |
addToRevEdges(structure.output, idx); | |
edges.set(idx, [structure.input, structure.output]); | |
addToRevEdges(structure.input, idx); | |
addToRevEdges(structure.output, idx); |
@@ -32,7 +32,7 @@ impl Where { | |||
|
|||
fn nested(&self, name: &str, model_id: TypeId) -> Self { | |||
let mut skip_models = self.skip_models.clone(); | |||
skip_models.insert(self.model_id, name.to_string()); | |||
skip_models.insert(self.model_id.name().unwrap().unwrap(), name.to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle potential errors without double 'unwrap()' calls to prevent panics
In lines 35 and 122, self.model_id.name().unwrap().unwrap()
is used. The double unwrap()
may lead to panics if the Option
or Result
values are None
or Err
. To ensure robustness, consider handling these cases properly.
Apply this diff to safely handle the potential None
or Err
values:
- skip_models.insert(self.model_id.name().unwrap().unwrap(), name.to_string());
+ let model_name = self.model_id.name()?.unwrap_or_default();
+ skip_models.insert(model_name, name.to_string());
...
- let model_name = self.model_id.name().unwrap().unwrap();
+ let model_name = self.model_id.name()?.unwrap_or_default();
Alternatively, you can handle the Option
and Result
explicitly:
if let Some(Ok(model_name)) = self.model_id.name() {
skip_models.insert(model_name.clone(), name.to_string());
} else {
// Handle the error or return early
}
Also applies to: 122-122
Awesome, the vivavox typegraph size went down to 1.4mb! |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #958 +/- ##
=======================================
Coverage 77.72% 77.72%
=======================================
Files 154 154
Lines 19154 19154
Branches 1930 1930
=======================================
Hits 14888 14888
Misses 4243 4243
Partials 23 23 ☔ View full report in Codecov by Sentry. |
// .unwrap_or(name) | ||
// }) | ||
.collect::<Vec<_>>(); | ||
keys.sort(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging is fun 🤕
|
||
export function listDuplicatesEnhanced(tg: TypeGraphDS, _rootIdx = 0) { | ||
// to <- from | ||
const reducedSetMap = new Map<number, number[]>(); | ||
const reducedSet = new Set<number>(); | ||
let cycleNo = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔥
└── [posts]: optional #81 | ||
└── item: union #80 | ||
├── variant_0: struct #75 | ||
│ └── [every]: optional #74 | ||
│ └── item: struct 'Post_where_excluding_User' #73 | ||
│ ├── [author]: optional #71 | ||
│ │ └── item: struct 'User_where_excluding_Post_and_User' #70 | ||
│ │ ├── [id]: optional #58 | ||
│ │ │ └── item: &_prisma_integer_filter_ex #16 | ||
│ │ ├── [name]: optional #59 | ||
│ │ │ └── item: &_prisma_string_filter_ex #33 | ||
│ │ └── [posts]: optional #68 | ||
│ │ └── item: union #67 | ||
│ │ ├── variant_0: struct #62 | ||
│ │ │ └── [every]: optional #61 | ||
│ │ │ └── item: &Post_where_excluding_User #60 | ||
│ │ ├── variant_1: struct #64 | ||
│ │ │ └── [some]: optional #63 | ||
│ │ │ └── item: &Post_where_excluding_User #60 | ||
│ │ └── variant_2: struct #66 | ||
│ │ └── [none]: optional #65 | ||
│ │ └── item: &Post_where_excluding_User #60 | ||
└── [posts]: optional #68 | ||
└── item: union #67 | ||
├── variant_0: struct #62 | ||
│ └── [every]: optional #61 | ||
│ └── item: struct 'Post_where_excluding_User' #60 | ||
│ ├── [author]: optional #58 | ||
│ │ └── item: &User_where #57 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good stuff!
Migration notes
Summary by CodeRabbit
New Features
Refactor
Bug Fixes