From 4812e371b0351e50608e5a84551a2f1c4f4e3d62 Mon Sep 17 00:00:00 2001 From: ig Date: Thu, 9 Mar 2023 10:52:31 +0100 Subject: [PATCH] Rewrite IsParentOfChild --- csharp/App/Backend/Database/Folder.cs | 1 - csharp/App/Backend/Database/User.cs | 15 ++++----------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/csharp/App/Backend/Database/Folder.cs b/csharp/App/Backend/Database/Folder.cs index 8a4785639..0867b4e50 100644 --- a/csharp/App/Backend/Database/Folder.cs +++ b/csharp/App/Backend/Database/Folder.cs @@ -26,7 +26,6 @@ public partial class Db return Folders.Where(f => f.ParentId == parent.Id); } - public IEnumerable GetDescendantFolders(Folder parent) { return parent.Traverse(GetChildFolders); diff --git a/csharp/App/Backend/Database/User.cs b/csharp/App/Backend/Database/User.cs index 682ecbc5b..22a65a0bd 100644 --- a/csharp/App/Backend/Database/User.cs +++ b/csharp/App/Backend/Database/User.cs @@ -30,17 +30,10 @@ public partial class Db public Boolean IsParentOfChild(User parent, User child) { - var parentPointer = child.ParentId; - - if (parent.Id == child.Id) - return true; - - while (parentPointer != null && parentPointer != parent.Id) - { - parentPointer = GetUserById(parentPointer).ParentId; - } - - return parentPointer == parent.Id; + return child + .Unfold(u => GetUserById(u.ParentId)) + .Select(u => u.Id) + .Contains(parent.Id); } public User? GetUserByEmail(String email) => Users.FirstOrDefault(u => u.Email == email);