mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-03 21:54:49 -04:00
The crawler is now fully multi-threaded
This commit is contained in:
parent
8e37505b8f
commit
ef84a969b7
@ -207,5 +207,22 @@ namespace Kyoo
|
||||
for (int i = 0; i < list.Count; i += countPerList)
|
||||
yield return list.GetRange(i, Math.Min(list.Count - i, countPerList));
|
||||
}
|
||||
|
||||
public static IEnumerable<T[]> BatchBy<T>(this IEnumerable<T> list, int countPerList)
|
||||
{
|
||||
T[] ret = new T[countPerList];
|
||||
int i = 0;
|
||||
|
||||
using IEnumerator<T> enumerator = list.GetEnumerator();
|
||||
while (enumerator.MoveNext())
|
||||
{
|
||||
ret[i] = enumerator.Current;
|
||||
i++;
|
||||
if (i < countPerList)
|
||||
continue;
|
||||
i = 0;
|
||||
yield return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -113,20 +113,17 @@ namespace Kyoo.Controllers
|
||||
.ToList();
|
||||
|
||||
// Todo batch wth higher numbers per list once multi-services has been implemented.
|
||||
|
||||
List<Task> tasks = shows
|
||||
|
||||
IEnumerable<Task> tasks = shows
|
||||
.Select(x => x.First())
|
||||
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken))
|
||||
.ToList();
|
||||
// TODO EXECUTION OF THE TASKS ARE CALCULATED DURING THE .ToList() CALL, NO BACHING/ASYNC IS DONE.
|
||||
foreach (List<Task> showTasks in tasks.BatchBy(1))
|
||||
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken));
|
||||
foreach (Task[] showTasks in tasks.BatchBy(30))
|
||||
await Task.WhenAll(showTasks);
|
||||
|
||||
|
||||
tasks = shows
|
||||
.SelectMany(x => x.Skip(1))
|
||||
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken))
|
||||
.ToList();
|
||||
foreach (List<Task> episodeTasks in tasks.BatchBy(1))
|
||||
.Select(x => RegisterFile(x, x.Substring(path.Length), library, cancellationToken));
|
||||
foreach (Task[] episodeTasks in tasks.BatchBy(50))
|
||||
await Task.WhenAll(episodeTasks);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user