[KOE-39] Cleaned up chunk determination code, which yields in cleaner release

This commit is contained in:
Patrick Simpson 2017-02-07 12:28:35 +01:00
parent 1bf1c846f1
commit 310cc48b63
1 changed files with 35 additions and 33 deletions

View File

@ -316,7 +316,7 @@ namespace Acacia.Features.GAB
}
}
private IItem FindNewestChunk()
private ChunkIndex? FindNewestChunkIndex()
{
if (Folder == null)
return null;
@ -326,13 +326,16 @@ namespace Acacia.Features.GAB
int i = 0;
foreach(IItem item in Folder.ItemsSorted("LastModificationTime", true))
{
if (ChunkIndex.Parse(item.Subject) != null)
return item;
item.Dispose();
using (item)
{
ChunkIndex? index = ChunkIndex.Parse(item.Subject);
if (index != null)
return index;
if (i > Constants.ZPUSH_GAB_NEWEST_MAX_CHECK)
return null;
++i;
}
}
return null;
}
@ -341,14 +344,14 @@ namespace Acacia.Features.GAB
try
{
// Find the newest chunk
using (IItem newest = FindNewestChunk())
ChunkIndex? newestChunkIndex = FindNewestChunkIndex();
if (newestChunkIndex == null)
{
if (newest == null)
CurrentSequence = null;
}
else
{
Logger.Instance.Trace(this, "Newest chunk: {0}", newest.Subject);
ChunkIndex? newestChunkIndex = ChunkIndex.Parse(newest.Subject);
Logger.Instance.Trace(this, "Newest chunk: {0}", newestChunkIndex.Value);
if (!CurrentSequence.HasValue || CurrentSequence.Value != newestChunkIndex?.numberOfChunks)
{
@ -378,7 +381,6 @@ namespace Acacia.Features.GAB
}
}
}
}
catch(Exception e)
{
Logger.Instance.Trace(this, "Exception determining sequence: {0}", e);