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