Frage

in my box application I have a specific structure where I need to return only the last folder on the tree to put files. That way, a recursive search probably will be too costly to run every single time when I need to upload something.

What's the better way:

a) Create my own search tree array to easily find my target folder and update it every time a new folder are created (no one are allowed to create folders via box app or box website)

b) Recursive requests, because 6 or 7 API requests isn't a real problem

c) Actually is there a better way to do this and I will show to you :)

I'm going into a) option because it sounds to me a good idea, but I'm wide open to answers and accept if I'm going to the wrong side.

EDIT:

Trying to clarify, my folder structure are something similar to:

Client 1/
 Folder 1/
  subfolder/
   subsubfolder/
 Folder 2/
  subfolder/
   subsubfolder/
    subsubsubfolder/
 […]
Client 2/
 Folder 1/
[…]

And I need to get the leaves of this tree (the children folders who aren't father too). The last folders of the tree in this example are: client1/folder1/subfolder/subsubfolder, client1/folder2/subfolder/subsubfolder/subsubsubfolder and client2/folder1.

War es hilfreich?

Lösung

If nobody is allowed to add subfolders, then you can just cache the ID of the deepest node.

But, I'm assuming there must be someone that can add nodes to the tree, so the deepest node must change periodically. It all really depends on how often it changes. If it is only every 10 times you want to do an upload, then maybe you should cache the ID, and have a periodic job that goes recursively through the folder structure, and gets the new deepest folder ID. That's your option b, and unless you're really unusual, most accounts do not have any folder that is more than 8 levels deep. You can also recurse through the folder structure with more than one thread, if you need to optimize your performance.

Andere Tipps

Not sure if I am understanding your question but if you are always trying to get the last (meaning last updated folder) you can use something like this

    DateTime lastHigh = new DateTime(1900,1,1);
    string highDir;
    foreach (string subdir in Directory.GetDirectories(path)){
        DirectoryInfo fi1 = new DirectoryInfo(subdir);
        DateTime created = fi1.LastWriteTime;

        if (created > lastHigh){
            highDir = subdir;
            lastHigh = created;
        }
    }
return highDir;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top