forked from extern/GetMoarFediverse
Do up to 2 * tags concurrent requests (#20)
This commit is contained in:
parent
44b47acbfe
commit
83ca6bb63b
@ -35,28 +35,30 @@ if (!File.Exists(importedPath))
|
|||||||
File.WriteAllText(importedPath, "");
|
File.WriteAllText(importedPath, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
ParallelOptions parallelOptions = new()
|
|
||||||
{
|
|
||||||
MaxDegreeOfParallelism = 8
|
|
||||||
};
|
|
||||||
|
|
||||||
var robotsFileParser = new RobotsFileParser();
|
var robotsFileParser = new RobotsFileParser();
|
||||||
var sitesRobotFile = new ConcurrentDictionary<string, RobotsFile>();
|
var sitesRobotFile = new ConcurrentDictionary<string, RobotsFile>();
|
||||||
await Parallel.ForEachAsync(Config.Instance.Sites, parallelOptions, async (site, _) =>
|
await Parallel.ForEachAsync(Config.Instance.Sites,
|
||||||
{
|
new ParallelOptions { MaxDegreeOfParallelism = Config.Instance.Sites.Length },
|
||||||
sitesRobotFile[site.Host] = await robotsFileParser.FromUriAsync(new Uri($"http://{site.Host}/robots.txt"));
|
async (site, _) =>
|
||||||
});
|
{
|
||||||
|
sitesRobotFile[site.Host] = await robotsFileParser.FromUriAsync(new Uri($"http://{site.Host}/robots.txt"));
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
List<(string host, string tag)> sitesTags;
|
List<(string host, string tag)> sitesTags;
|
||||||
|
int numberOfTags;
|
||||||
if (Config.Instance.MastodonPostgresConnectionString.HasValue())
|
if (Config.Instance.MastodonPostgresConnectionString.HasValue())
|
||||||
{
|
{
|
||||||
var tags = await MastodonConnectionHelper.GetFollowedTagsAsync();
|
var tags = await MastodonConnectionHelper.GetFollowedTagsAsync();
|
||||||
|
numberOfTags = tags.Count;
|
||||||
sitesTags = Config.Instance.Sites
|
sitesTags = Config.Instance.Sites
|
||||||
.SelectMany(s => tags.Select(t => (s.Host, t)))
|
.SelectMany(s => tags.Select(t => (s.Host, t)))
|
||||||
|
.OrderBy(e => e.t)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
numberOfTags = Config.Instance.Tags.Length;
|
||||||
sitesTags = Config.Instance.Sites
|
sitesTags = Config.Instance.Sites
|
||||||
.SelectMany(s => Config.Instance.Tags.Select(tag => (s.Host, tag)))
|
.SelectMany(s => Config.Instance.Tags.Select(tag => (s.Host, tag)))
|
||||||
.Concat(Config.Instance.Sites.SelectMany(s => s.SiteSpecificTags.Select(tag => (s.Host, tag))))
|
.Concat(Config.Instance.Sites.SelectMany(s => s.SiteSpecificTags.Select(tag => (s.Host, tag))))
|
||||||
@ -67,7 +69,7 @@ else
|
|||||||
var importedList = File.ReadAllLines(importedPath).ToList();
|
var importedList = File.ReadAllLines(importedPath).ToList();
|
||||||
var imported = importedList.ToHashSet();
|
var imported = importedList.ToHashSet();
|
||||||
var statusesToLoadBag = new ConcurrentBag<string>();
|
var statusesToLoadBag = new ConcurrentBag<string>();
|
||||||
await Parallel.ForEachAsync(sitesTags, parallelOptions, async (st, _) =>
|
await Parallel.ForEachAsync(sitesTags, new ParallelOptions{MaxDegreeOfParallelism = numberOfTags * 2}, async (st, _) =>
|
||||||
{
|
{
|
||||||
var (site, tag) = st;
|
var (site, tag) = st;
|
||||||
Console.WriteLine($"Fetching tag #{tag} from {site}");
|
Console.WriteLine($"Fetching tag #{tag} from {site}");
|
||||||
|
Loading…
Reference in New Issue
Block a user