1
0
mirror of https://github.com/Kopano-dev/kopano-ol-extension.git synced 2023-10-10 13:37:40 +02:00

[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

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,12 +326,15 @@ 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 (i > Constants.ZPUSH_GAB_NEWEST_MAX_CHECK) if (index != null)
return null; return index;
++i; if (i > Constants.ZPUSH_GAB_NEWEST_MAX_CHECK)
return null;
++i;
}
} }
return null; return null;
} }
@ -341,39 +344,38 @@ 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}", newestChunkIndex.Value);
if (!CurrentSequence.HasValue || CurrentSequence.Value != newestChunkIndex?.numberOfChunks)
{ {
Logger.Instance.Trace(this, "Newest chunk: {0}", newest.Subject); // Sequence has changed. Delete contacts
ChunkIndex? newestChunkIndex = ChunkIndex.Parse(newest.Subject); Logger.Instance.Trace(this, "Rechunked, deleting contacts");
ClearContacts();
if (!CurrentSequence.HasValue || CurrentSequence.Value != newestChunkIndex?.numberOfChunks) // Determine new sequence
if (newestChunkIndex == null)
{ {
// Sequence has changed. Delete contacts using (IStorageItem index = GetIndexItem())
Logger.Instance.Trace(this, "Rechunked, deleting contacts");
ClearContacts();
// Determine new sequence
if (newestChunkIndex == null)
{ {
using (IStorageItem index = GetIndexItem()) if (index != null)
{ index.Delete();
if (index != null)
index.Delete();
}
} }
else }
else
{
int numberOfChunks = newestChunkIndex.Value.numberOfChunks;
using (IStorageItem index = GetIndexItem())
{ {
int numberOfChunks = newestChunkIndex.Value.numberOfChunks; index.GetUserProperty<int>(PROP_CURRENT_SEQUENCE, true).Value = numberOfChunks;
using (IStorageItem index = GetIndexItem()) index.GetUserProperty<string>(PROP_LAST_PROCESSED, true).Value = CreateChunkStateString(numberOfChunks);
{ index.Save();
index.GetUserProperty<int>(PROP_CURRENT_SEQUENCE, true).Value = numberOfChunks;
index.GetUserProperty<string>(PROP_LAST_PROCESSED, true).Value = CreateChunkStateString(numberOfChunks);
index.Save();
}
} }
} }
} }