From e09c2e89e2d5a8d22670989abeb1b89b13e695ff Mon Sep 17 00:00:00 2001 From: Luiz Zen Date: Sun, 24 Apr 2022 19:13:04 -0300 Subject: [PATCH] Simplified query --- .vscode/launch.json | 4 +- .../Repositories/LiveProjectRepository.cs | 56 +--------- TEMP.txt | 100 ++++++++++++++++++ 3 files changed, 106 insertions(+), 54 deletions(-) create mode 100644 TEMP.txt diff --git a/.vscode/launch.json b/.vscode/launch.json index 36534f1..7e6feaf 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,9 +12,9 @@ // If you have changed target frameworks, make sure to update the program path. "program": "${workspaceFolder}/bin/Debug/net6.0/als-tools.dll", //"args": ["--locate=HG2;bx_tunner", "--folder=/Users/zenluiz/Desktop/Testes ALS"], - //"args": ["--locate=radiator"], + "args": ["--locate=kickbox;replika"], // "args": ["--list"], - "args": ["--initdb", "--folder=/Users/zenluiz/Desktop/Testes ALS"], + // "args": ["--initdb", "--folder=/Users/zenluiz/Desktop/Testes ALS"], // "args": ["--initdb", "--folder=/Users/zenluiz/Splice"], "cwd": "${workspaceFolder}", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/Infrastructure/Repositories/LiveProjectRepository.cs b/Infrastructure/Repositories/LiveProjectRepository.cs index a61e63a..37dba97 100644 --- a/Infrastructure/Repositories/LiveProjectRepository.cs +++ b/Infrastructure/Repositories/LiveProjectRepository.cs @@ -39,64 +39,16 @@ public IEnumerable GetAllProjects() public IEnumerable GetProjectsContainingPlugins(string[] pluginsToLocate) { - // var col = liteDb.GetCollection("LiveProject"); - - // var pluginsList = pluginsToLocate - - // var projects = col - // .Query() - // .Where(proj => proj.Plugins != null && proj.Plugins.Any(k => pluginsToLocate.Any(x => k.Name.Contains(x, StringComparison.InvariantCultureIgnoreCase)))) - // .Select(p => p) - // .ToEnumerable(); - - // var projects = col - // .Query() - // .Where(proj => proj.Plugins.Where(plugin => pluginsToLocate.Contains(plugin.Name)).Any()) - // .Select(p => p) - // .ToEnumerable(); - - // var projects = col - // .Query() - // .Where(proj => - // proj.Plugins.Where(plugin => - // pluginsToLocate.Any(p => p.Contains(plugin.Name, StringComparison.InvariantCultureIgnoreCase)) - // ).Any() - // ) - // .Select(p => p) - // .ToEnumerable(); - - // var projects = col - // .Include(x => x.Plugins) - // .FindAll() - // .Where(p => p.Plugins.Intersect(pluginsToLocate)) - - //TODO: implement it correctly, using DB query + //TODO: implement it correctly, using DB query var projects = GetAllProjects(); IList res = new List(); - foreach (var p in projects) + foreach (var proj in projects) { - var plugins = p.Tracks.Select(x => x.Plugins).SelectMany(x => x); - if (plugins.Any(x => pluginsToLocate.Any(y => x.Key.Contains(y, StringComparison.InvariantCultureIgnoreCase)))) - res.Add(p); - // if (p.Plugins.Any(x => pluginsToLocate.Any(y => x.Key.Contains(y, StringComparison.InvariantCultureIgnoreCase)))) - // res.Add(p); + if (proj.Tracks.Any(track => track.Plugins.Any(plugin => pluginsToLocate.Any(plugToLocate => plugin.Key.Contains(plugToLocate, StringComparison.InvariantCultureIgnoreCase))))) + res.Add(proj); } return res.AsEnumerable(); - - // var pluginToLocate = pluginsToLocate[0]; - // var col = liteDb.GetCollection("LiveProject"); - - // var query = @"SELECT { $.*, $.Plugins[*] FROM LiveProject } WHERE $.Plugins[*].Title LIKE '%" + pluginToLocate + "%'"; - // var s = liteDb.Execute(query).ToList(); - - // var res = col.Query() - // .Where(proj => proj.Plugins.Any(p => p.Key.Contains(pluginToLocate, StringComparison.InvariantCultureIgnoreCase)).Any()) - // .Select(x => x); - - // return res.ToEnumerable(); - - // return null; } public bool Insert(LiveProject project) diff --git a/TEMP.txt b/TEMP.txt new file mode 100644 index 0000000..e16df07 --- /dev/null +++ b/TEMP.txt @@ -0,0 +1,100 @@ + // var col = liteDb.GetCollection("LiveProject"); + + // var colall = liteDb.GetCollection("LiveProject"); + // var all = colall.FindAll().Where(pr => pr.Tracks.Any(tr => tr.Plugins.Any(pl => pl.Value.Name.ToLower() == "decapitator"))).ToList(); + + // // var pluginsList = pluginsToLocate + + // // var q1 = col.Find(proj => proj.Tracks != null && proj.Tracks.Any(track => track.Plugins != null && track + // // .Plugins.Any(plugin => pluginsToLocate.Contains(plugin.Key)) + // // )).ToList(); + + // var q1 = col.Query().Where(proj => proj.Name == "Industrial Acid Techno Youtube.als"); + // // var col1 = q1.Select(x => x); + // var col1 = q1.First(); + + // // var proj = col1.First(); + + // var a = q1.Where(x => x.Tracks.Where(x => x.Plugins != null && x.Plugins.Count > 0).Any()).Select(x => x).ToList(); + + + // // var b = col.Query().Where(x => x.Tracks.Where(x => x.Plugins != null && x.Plugins.Any(p => p.Value.Name == "Decapitator")).Any()).Select(x => x).ToList(); + // // {LiteDB.LiteException: Any/All requires simple parameter on left side. Eg: `x => x.Phones.Select(p => p.Number).Any(n => n > 5)` + + // // var b = col.Query().Where(x => x.Tracks.Where(x => x.Plugins != null && x.Plugins.Keys.Any(k => k.Equals("Decapitator"))).Any()).Select(x => x).ToList(); + // // var b = col.Query().Where(x => x.Tracks.Where(x => x.Plugins.Where(p => p.Value.Name == "Decapitator").Count() > 0).Any()).Select(x => x).ToList(); + // var c = col + // .Query() + // .Where(proj => proj.Name == "Industrial Acid Techno Youtube.als") + // .Where(x => x.Tracks.Where(x => x.Plugins.Values.Where(v => v.Name.Length > 5).Count() > 0).Count() > 0) + // .Select(x => x) + // .ToList(); + + // var q1 = col.Find(proj => proj.Tracks.Count > 40) + // .Select(x => x.Tracks) + // .ToList(); + + // var q2 = col.FindAll().ToList(); + + // var q3 = col.Query().Select(x => x).ToList(); + + + + // var p1 = col + // .Query() + // .Where(proj => proj.Tracks.Any(track => track.Name.Length > 10)) + // .Select(proj => proj) + // .ToList(); + + // var projects = col + // .Query() + // .Where(proj => proj + // .Tracks.Any(track => track + // .Plugins.Any(plugin => pluginsToLocate.Contains(plugin.Key)) + // ) + // ) + // .Select(proj => proj) + // .ToEnumerable(); + + //return null; + + // var projects1 = col + // .Query() + // .Where(proj => proj.Plugins != null && proj.Plugins.Any(k => pluginsToLocate.Any(x => k.Name.Contains(x, StringComparison.InvariantCultureIgnoreCase)))) + // .Select(p => p) + // .ToEnumerable(); + + // var projects2 = col + // .Query() + // .Where(proj => proj.Plugins.Where(plugin => pluginsToLocate.Contains(plugin.Name)).Any()) + // .Select(p => p) + // .ToEnumerable(); + + // var projects3 = col + // .Query() + // .Where(proj => + // proj.Plugins.Where(plugin => + // pluginsToLocate.Any(p => p.Contains(plugin.Name, StringComparison.InvariantCultureIgnoreCase)) + // ).Any() + // ) + // .Select(p => p) + // .ToEnumerable(); + + // var projects4 = col + // .Include(x => x.Plugins) + // .FindAll() + // .Where(p => p.Plugins.Intersect(pluginsToLocate)) + + // var pluginToLocate = pluginsToLocate[0]; + // var col = liteDb.GetCollection("LiveProject"); + + // var query = @"SELECT { $.*, $.Plugins[*] FROM LiveProject } WHERE $.Plugins[*].Title LIKE '%" + pluginToLocate + "%'"; + // var s = liteDb.Execute(query).ToList(); + + // var res = col.Query() + // .Where(proj => proj.Plugins.Any(p => p.Key.Contains(pluginToLocate, StringComparison.InvariantCultureIgnoreCase)).Any()) + // .Select(x => x); + + // return res.ToEnumerable(); + + // return null; \ No newline at end of file