From c1f0e24d216aa23b79e367ffe4e1e4b58b1a8e7d Mon Sep 17 00:00:00 2001 From: Abdullah Atta Date: Fri, 1 Aug 2025 11:39:18 +0500 Subject: [PATCH] sync: update LastAccessTime on push, pull & register --- Notesnook.API/Hubs/SyncV2Hub.cs | 13 +++++++++---- Notesnook.API/Services/SyncDeviceService.cs | 11 ++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Notesnook.API/Hubs/SyncV2Hub.cs b/Notesnook.API/Hubs/SyncV2Hub.cs index cf244cd..8b62d92 100644 --- a/Notesnook.API/Hubs/SyncV2Hub.cs +++ b/Notesnook.API/Hubs/SyncV2Hub.cs @@ -158,7 +158,7 @@ namespace Notesnook.API.Hubs private static async IAsyncEnumerable PrepareChunks(Func>>[] collections, string[] types, string userId, string[] ids, int size, bool resetSync, long maxBytes) { - var chunksProcessed = 0; + var itemsProcessed = 0; for (int i = 0; i < collections.Length; i++) { var type = types[i]; @@ -180,11 +180,12 @@ namespace Notesnook.API.Hubs totalBytes += item.Length + METADATA_BYTES; if (totalBytes >= maxBytes) { + itemsProcessed += chunk.Count; yield return new SyncTransferItemV2 { Items = chunk, Type = type, - Count = chunksProcessed + Count = itemsProcessed }; totalBytes = 0; @@ -194,11 +195,12 @@ namespace Notesnook.API.Hubs } if (chunk.Count > 0) { + itemsProcessed += chunk.Count; yield return new SyncTransferItemV2 { Items = chunk, Type = type, - Count = chunksProcessed + Count = itemsProcessed }; } } @@ -211,9 +213,12 @@ namespace Notesnook.API.Hubs SyncEventCounterSource.Log.FetchV2(); - var deviceService = new SyncDeviceService(new SyncDevice(userId, deviceId)); + var device = new SyncDevice(userId, deviceId); + var deviceService = new SyncDeviceService(device); if (!deviceService.IsDeviceRegistered()) deviceService.RegisterDevice(); + device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); + var isResetSync = deviceService.IsSyncReset(); if (!deviceService.IsUnsynced() && !deviceService.IsSyncPending() && diff --git a/Notesnook.API/Services/SyncDeviceService.cs b/Notesnook.API/Services/SyncDeviceService.cs index 0bfe3b6..7b136ce 100644 --- a/Notesnook.API/Services/SyncDeviceService.cs +++ b/Notesnook.API/Services/SyncDeviceService.cs @@ -58,8 +58,12 @@ namespace Notesnook.API.Services private readonly void SetMetadata(string metadataKey, string value) { - var path = CreateFilePath(userId, deviceId, metadataKey); - File.WriteAllText(path, value); + try + { + var path = CreateFilePath(userId, deviceId, metadataKey); + File.WriteAllText(path, value); + } + catch (DirectoryNotFoundException) { } } } @@ -88,7 +92,6 @@ namespace Notesnook.API.Services if (IsSyncReset()) return []; try { - device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); var unsyncedIds = GetUnsyncedIds(); lock (device.DeviceId) { @@ -176,6 +179,7 @@ namespace Notesnook.API.Services public void AddIdsToOtherDevices(List ids) { + device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); foreach (string id in ListDevices()) { if (id == device.DeviceId || IsSyncReset(id)) return; @@ -198,6 +202,7 @@ namespace Notesnook.API.Services Directory.Delete(device.UserDeviceDirectoryPath, true); Directory.CreateDirectory(device.UserDeviceDirectoryPath); File.Create(device.ResetSyncFilePath).Close(); + device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); } }