Skip to content

Commit

Permalink
- Reduce threads to 1 to make Google Drive index stable
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Feb 16, 2022
1 parent f2f30d8 commit 3ef96af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/OpenDirectoryDownloader/DirectoryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,15 @@ public static async Task<WebDirectory> ParseHtml(WebDirectory webDirectory, stri
}
}

if (googleDriveIndexType is not null)
{
if (OpenDirectoryIndexer.Session.MaxThreads != 1)
{
OpenDirectoryIndexer.Session.MaxThreads = 1;
Logger.Warn($"Reduce threads to 1 because of Google Drive index");
}
}

switch (googleDriveIndexType)
{
case GoogleDriveIndexMapping.BhadooIndex:
Expand Down Expand Up @@ -533,7 +542,7 @@ private static WebDirectory ParseHfsListing(ref string baseUrl, WebDirectory par
{
string fileName = new Uri(fullUrl).AbsolutePath;
string size = divElement.QuerySelector(".item-size").TextContent.Trim();

parsedWebDirectory.Files.Add(new WebFile
{
Url = fullUrl,
Expand Down
6 changes: 6 additions & 0 deletions src/OpenDirectoryDownloader/OpenDirectoryIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,12 @@ private async Task WebDirectoryProcessor(ConcurrentQueue<WebDirectory> queue, st

do
{
if (RunningWebDirectoryThreads + 1 > Session.MaxThreads)
{
Logger.Info($"Stopped thread because it's there are more threads ({RunningWebDirectoryThreads + 1}) running than wanted ({Session.MaxThreads})");
break;
}

Interlocked.Increment(ref RunningWebDirectoryThreads);

if (queue.TryDequeue(out WebDirectory webDirectory))
Expand Down

0 comments on commit 3ef96af

Please sign in to comment.