Skip to content

Commit

Permalink
compact debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
quinchs committed Mar 10, 2024
1 parent 4fcd9d5 commit 3ed6b58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 51 deletions.
46 changes: 0 additions & 46 deletions examples/EdgeDB.Examples.CSharp/Examples/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,52 +32,6 @@ public async Task ExecuteAsync(EdgeDBClient client)
{
try
{
// depth of 4
var data = new Person[]
{
new Person
{
Email = "[email protected]",
Name = "test1",
},
new Person
{
Email = "[email protected]",
Name = "test2",
BestFriend = new Person
{
Email = "[email protected]",
Name = "test3",
Friends = new List<Person>()
{
new Person()
{
Name = "test4",
Email = "[email protected]",
BestFriend = new Person()
{
Name = "test4.1",
Email = "[email protected]"
}
},
new Person()
{
Name = "test5",
Email = "[email protected]",
BestFriend = new Person()
{
Name = "test5.1",
Email = "[email protected]"
}
}
}
}
}
};

var query = await QueryBuilder.For(data,
x => QueryBuilder.Insert(x)
).CompileAsync(client, true);
await QueryBuilderDemo(client);
}
catch (Exception x)

Check warning on line 37 in examples/EdgeDB.Examples.CSharp/Examples/QueryBuilder.cs

View workflow job for this annotation

GitHub Actions / Run test suite

The variable 'x' is declared but never used

Check warning on line 37 in examples/EdgeDB.Examples.CSharp/Examples/QueryBuilder.cs

View workflow job for this annotation

GitHub Actions / Run test suite

The variable 'x' is declared but never used
Expand Down
21 changes: 16 additions & 5 deletions src/EdgeDB.Net.QueryBuilder/Compiled/DebugCompiledQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,11 @@ private static string CreateDebugText(string query, Dictionary<string, object?>
else
{
sb.AppendLine(query);
sb.AppendLine();
}

if (variables.Count > 0)
{
sb.AppendLine();
sb.AppendLine("Variables: ");

foreach (var (name, value) in variables)
Expand All @@ -178,20 +178,29 @@ private static string CreateDebugText(string query, Dictionary<string, object?>

private static List<List<QuerySpan>> CreateMarkerView(LinkedList<QuerySpan> spans)
{
var ordered = new Queue<QuerySpan>(spans.OrderBy(x => x.Range.End.Value - x.Range.Start.Value)); // order by 'size'
var orderedTemp = spans.OrderBy(x => x.Range.End.Value - x.Range.Start.Value).ToList();
var ordered = new Queue<QuerySpan>(orderedTemp); // order by 'size'
var result = new List<List<QuerySpan>>();
var row = new List<QuerySpan>();

while (ordered.TryDequeue(out var span))
{
var head = row.LastOrDefault();
if (head is null)
foreach (var prevRow in result)
{
if (prevRow.All(y => !span.Range.Overlaps(y.Range)))
{
prevRow.Add(span);
goto end_iter;
}
}

if (row.Count == 0)
{
row.Add(span);
continue;
}

if (head.Range.End.Value >= span.Range.Start.Value)
if (row.Any(x => x.Range.Overlaps(span.Range)))
{
// overlap
result.Add(row);
Expand All @@ -200,6 +209,8 @@ private static List<List<QuerySpan>> CreateMarkerView(LinkedList<QuerySpan> span
}

row.Add(span);

end_iter: ;
}

result.Add(row);
Expand Down
9 changes: 9 additions & 0 deletions src/EdgeDB.Net.QueryBuilder/Extensions/RangeExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace EdgeDB;

public static class RangeExtensions
{
public static bool Overlaps(this Range a, Range b)
{
return a.Start.Value < b.End.Value && b.Start.Value < a.End.Value;
}
}

0 comments on commit 3ed6b58

Please sign in to comment.