mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-08-16 05:20:19 +02:00
sync: update LastAccessTime on push, pull & register
This commit is contained in:
@@ -158,7 +158,7 @@ namespace Notesnook.API.Hubs
|
|||||||
|
|
||||||
private static async IAsyncEnumerable<SyncTransferItemV2> PrepareChunks(Func<string, string[], bool, int, Task<IAsyncCursor<SyncItem>>>[] collections, string[] types, string userId, string[] ids, int size, bool resetSync, long maxBytes)
|
private static async IAsyncEnumerable<SyncTransferItemV2> PrepareChunks(Func<string, string[], bool, int, Task<IAsyncCursor<SyncItem>>>[] 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++)
|
for (int i = 0; i < collections.Length; i++)
|
||||||
{
|
{
|
||||||
var type = types[i];
|
var type = types[i];
|
||||||
@@ -180,11 +180,12 @@ namespace Notesnook.API.Hubs
|
|||||||
totalBytes += item.Length + METADATA_BYTES;
|
totalBytes += item.Length + METADATA_BYTES;
|
||||||
if (totalBytes >= maxBytes)
|
if (totalBytes >= maxBytes)
|
||||||
{
|
{
|
||||||
|
itemsProcessed += chunk.Count;
|
||||||
yield return new SyncTransferItemV2
|
yield return new SyncTransferItemV2
|
||||||
{
|
{
|
||||||
Items = chunk,
|
Items = chunk,
|
||||||
Type = type,
|
Type = type,
|
||||||
Count = chunksProcessed
|
Count = itemsProcessed
|
||||||
};
|
};
|
||||||
|
|
||||||
totalBytes = 0;
|
totalBytes = 0;
|
||||||
@@ -194,11 +195,12 @@ namespace Notesnook.API.Hubs
|
|||||||
}
|
}
|
||||||
if (chunk.Count > 0)
|
if (chunk.Count > 0)
|
||||||
{
|
{
|
||||||
|
itemsProcessed += chunk.Count;
|
||||||
yield return new SyncTransferItemV2
|
yield return new SyncTransferItemV2
|
||||||
{
|
{
|
||||||
Items = chunk,
|
Items = chunk,
|
||||||
Type = type,
|
Type = type,
|
||||||
Count = chunksProcessed
|
Count = itemsProcessed
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,9 +213,12 @@ namespace Notesnook.API.Hubs
|
|||||||
|
|
||||||
SyncEventCounterSource.Log.FetchV2();
|
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();
|
if (!deviceService.IsDeviceRegistered()) deviceService.RegisterDevice();
|
||||||
|
|
||||||
|
device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
|
|
||||||
var isResetSync = deviceService.IsSyncReset();
|
var isResetSync = deviceService.IsSyncReset();
|
||||||
if (!deviceService.IsUnsynced() &&
|
if (!deviceService.IsUnsynced() &&
|
||||||
!deviceService.IsSyncPending() &&
|
!deviceService.IsSyncPending() &&
|
||||||
|
|||||||
@@ -58,8 +58,12 @@ namespace Notesnook.API.Services
|
|||||||
|
|
||||||
private readonly void SetMetadata(string metadataKey, string value)
|
private readonly void SetMetadata(string metadataKey, string value)
|
||||||
{
|
{
|
||||||
var path = CreateFilePath(userId, deviceId, metadataKey);
|
try
|
||||||
File.WriteAllText(path, value);
|
{
|
||||||
|
var path = CreateFilePath(userId, deviceId, metadataKey);
|
||||||
|
File.WriteAllText(path, value);
|
||||||
|
}
|
||||||
|
catch (DirectoryNotFoundException) { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +92,6 @@ namespace Notesnook.API.Services
|
|||||||
if (IsSyncReset()) return [];
|
if (IsSyncReset()) return [];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
|
||||||
var unsyncedIds = GetUnsyncedIds();
|
var unsyncedIds = GetUnsyncedIds();
|
||||||
lock (device.DeviceId)
|
lock (device.DeviceId)
|
||||||
{
|
{
|
||||||
@@ -176,6 +179,7 @@ namespace Notesnook.API.Services
|
|||||||
|
|
||||||
public void AddIdsToOtherDevices(List<string> ids)
|
public void AddIdsToOtherDevices(List<string> ids)
|
||||||
{
|
{
|
||||||
|
device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
foreach (string id in ListDevices())
|
foreach (string id in ListDevices())
|
||||||
{
|
{
|
||||||
if (id == device.DeviceId || IsSyncReset(id)) return;
|
if (id == device.DeviceId || IsSyncReset(id)) return;
|
||||||
@@ -198,6 +202,7 @@ namespace Notesnook.API.Services
|
|||||||
Directory.Delete(device.UserDeviceDirectoryPath, true);
|
Directory.Delete(device.UserDeviceDirectoryPath, true);
|
||||||
Directory.CreateDirectory(device.UserDeviceDirectoryPath);
|
Directory.CreateDirectory(device.UserDeviceDirectoryPath);
|
||||||
File.Create(device.ResetSyncFilePath).Close();
|
File.Create(device.ResetSyncFilePath).Close();
|
||||||
|
device.LastAccessTime = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user