Skip to content
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

Timeout because of large result set #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 45 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,25 @@ private void GenerateCache()
}
}

private int CountInCache(string searchChar)
{
var count = 0;
foreach (var key in Cache.ValueToIdCache.Keys)
{

if (key.StartsWith("CN=", true, null))
{
var sub = key.Substring(3);
if (sub.StartsWith(searchChar, true, null)){
count = count + 1;
}


}
}
return count;
}

private void AutoSplit()
{
char firstChar;
Expand Down Expand Up @@ -519,19 +538,38 @@ private void AutoSplit()
}
}

private void RecursiveQuerySplit(string prefix, int depth)
{
if (depth > 100) return; // Prevent going too deep

var results = CountInCache(prefix);
if (results == 0){
return;
}
if (results < threshold)
{
List<ADObject> objects = ADWSUtils.GetObjects("(cn=" + prefix + "*)");
CreateOutput(objects, prefix);
objects.Clear();
}
else
{
// If the results are too many, split further
foreach (char c in "abcdefghijklmnopqrstuvwxyz0123456789")
{
RecursiveQuerySplit(prefix + c, depth + 1); // Go one level deeper
}
}

}

private void ParseAutosplitObjects(string str1, string str2)
{
foreach (char c1 in str1)
{
if (deep)
{
//Gather 2nd depth level
foreach (char c2 in str2)
{
List<ADObject> objects = ADWSUtils.GetObjects("(cn=" + c1 + c2 + "*)");
CreateOutput(objects, c1.ToString() + c2.ToString());
objects.Clear();
}
RecursiveQuerySplit(c1.ToString(), 1);
//Gather non alphanumeric in 2nd depth level
List<ADObject> adobjects = ADWSUtils.GetObjects("(&(cn=" + c1 + "*)(!(cn=" + c1 + "a*))(!(cn=" + c1 + "b*))(!(cn=" + c1 + "c*))(!(cn=" + c1 + "d*))(!(cn=" + c1 + "e*))(!(cn=" + c1 + "f*))(!(cn=" + c1 + "g*))(!(cn=" + c1 + "h*))(!(cn=" + c1 + "i*))(!(cn=" + c1 + "j*))(!(cn=" + c1 + "k*))(!(cn=" + c1 + "l*))(!(cn=" + c1 + "m*))(!(cn=" + c1 + "n*))(!(cn=" + c1 + "o*))(!(cn=" + c1 + "p*))(!(cn=" + c1 + "q*))(!(cn=" + c1 + "r*))(!(cn=" + c1 + "s*))(!(cn=" + c1 + "t*))(!(cn=" + c1 + "u*))(!(cn=" + c1 + "v*))(!(cn=" + c1 + "w*))(!(cn=" + c1 + "x*))(!(cn=" + c1 + "y*))(!(cn=" + c1 + "z*))(!(cn=" + c1 + "0*))(!(cn=" + c1 + "1*))(!(cn=" + c1 + "2*))(!(cn=" + c1 + "3*))(!(cn=" + c1 + "4*))(!(cn=" + c1 + "5*))(!(cn=" + c1 + "6*))(!(cn=" + c1 + "7*))(!(cn=" + c1 + "8*))(!(cn=" + c1 + "9*)))");
CreateOutput(adobjects, c1.ToString() + "_nonchars_");
Expand Down