public Dictionary<byte[], long> StreamsToLoad(ActivityStream stream, long timestamp = 0)
{
AddOrUpdateStreamsToLoadWith(streamsToLoad, stream, timestamp);
Stack<byte[]> streamsToCrawl = new Stack<byte[]>();
streamsToCrawl.Push(stream.StreamId);
while (streamsToCrawl.Count > 0)
{
Guard_AgainstStupidity();
// Load next stream.
var currentId = streamsToCrawl.Pop();
var current = streamStore.Get(currentId) ?? ActivityStream.Empty;
long currentExpiresAt = current.ExpiresAt;
streamsToLoad.TryGetValue(current.StreamId, out currentExpiresAt);
if (ActivityStream.IsEmpty(current)) continue;
// Crawl only first level attached streams.
foreach (var nested in current.AttachedStreams)
{
if (IsCrawled(nested)) continue;
streamsToCrawl.Push(nested.StreamId);
var nestedShouldExpireAt = currentExpiresAt < nested.ExpiresAt ? currentExpiresAt : nested.ExpiresAt;
AddOrUpdateStreamsToLoadWith(streamsToLoad, nested, nestedShouldExpireAt);
}
}
return streamsToLoad;
}