From 7b76f2c238d47aaeacf4399f013dc8ca59c12e11 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 28 Jul 2016 21:41:45 -0400 Subject: [PATCH] Incremental sync only every 30 minutes --- src/App/Abstractions/Services/ISyncService.cs | 4 +++- src/App/App.cs | 2 +- src/App/Services/SyncService.cs | 11 +++++++++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/App/Abstractions/Services/ISyncService.cs b/src/App/Abstractions/Services/ISyncService.cs index 15f2abe81..8515bf906 100644 --- a/src/App/Abstractions/Services/ISyncService.cs +++ b/src/App/Abstractions/Services/ISyncService.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; namespace Bit.App.Abstractions { @@ -9,6 +10,7 @@ namespace Bit.App.Abstractions Task SyncDeleteFolderAsync(string id); Task SyncDeleteSiteAsync(string id); Task FullSyncAsync(); + Task IncrementalSyncAsync(TimeSpan syncThreshold); Task IncrementalSyncAsync(); } } diff --git a/src/App/App.cs b/src/App/App.cs index 7f0180b0a..6e05a5bc3 100644 --- a/src/App/App.cs +++ b/src/App/App.cs @@ -125,7 +125,7 @@ namespace Bit.App { try { - await _syncService.IncrementalSyncAsync(); + await _syncService.IncrementalSyncAsync(TimeSpan.FromMinutes(30)); break; } catch(WebException) diff --git a/src/App/Services/SyncService.cs b/src/App/Services/SyncService.cs index 5678fe538..604b670fe 100644 --- a/src/App/Services/SyncService.cs +++ b/src/App/Services/SyncService.cs @@ -167,6 +167,17 @@ namespace Bit.App.Services return true; } + public async Task IncrementalSyncAsync(TimeSpan syncThreshold) + { + DateTime? lastSync = _settings.GetValueOrDefault(LastSyncKey); + if(lastSync != null && DateTime.UtcNow - lastSync.Value < syncThreshold) + { + return false; + } + + return await IncrementalSyncAsync(); + } + public async Task IncrementalSyncAsync() { if(!_authService.IsAuthenticated)