From fa2f53ff7a8e274eda5cc9afede291aa71fa451a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 2 Dec 2025 21:03:57 +0800 Subject: [PATCH] :bug: Fix file reference created with wrong date --- DysonNetwork.Drive/AppDatabase.cs | 1 - DysonNetwork.Drive/Storage/FileReferenceService.cs | 5 ++++- DysonNetwork.Pass/Handlers/ActionLogFlushHandler.cs | 3 ++- DysonNetwork.Shared/Data/SoftDeleteExtension.cs | 2 +- DysonNetwork.Shared/Models/CloudFile.cs | 2 +- 5 files changed, 8 insertions(+), 5 deletions(-) diff --git a/DysonNetwork.Drive/AppDatabase.cs b/DysonNetwork.Drive/AppDatabase.cs index 2eb7b08..386463b 100644 --- a/DysonNetwork.Drive/AppDatabase.cs +++ b/DysonNetwork.Drive/AppDatabase.cs @@ -6,7 +6,6 @@ using DysonNetwork.Shared.Data; using DysonNetwork.Shared.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Design; -using Microsoft.EntityFrameworkCore.Query; using NodaTime; using Quartz; using TaskStatus = DysonNetwork.Drive.Storage.Model.TaskStatus; diff --git a/DysonNetwork.Drive/Storage/FileReferenceService.cs b/DysonNetwork.Drive/Storage/FileReferenceService.cs index 4127c76..dd577e8 100644 --- a/DysonNetwork.Drive/Storage/FileReferenceService.cs +++ b/DysonNetwork.Drive/Storage/FileReferenceService.cs @@ -58,12 +58,15 @@ public class FileReferenceService(AppDatabase db, FileService fileService, ICach Duration? duration = null ) { + var now = SystemClock.Instance.GetCurrentInstant(); var data = fileId.Select(id => new SnCloudFileReference { FileId = id, Usage = usage, ResourceId = resourceId, - ExpiredAt = expiredAt ?? SystemClock.Instance.GetCurrentInstant() + duration + ExpiredAt = expiredAt ?? now + duration, + CreatedAt = now, + UpdatedAt = now }).ToList(); await db.BulkInsertAsync(data); return data; diff --git a/DysonNetwork.Pass/Handlers/ActionLogFlushHandler.cs b/DysonNetwork.Pass/Handlers/ActionLogFlushHandler.cs index 74b16b8..5833b69 100644 --- a/DysonNetwork.Pass/Handlers/ActionLogFlushHandler.cs +++ b/DysonNetwork.Pass/Handlers/ActionLogFlushHandler.cs @@ -13,9 +13,10 @@ public class ActionLogFlushHandler(IServiceProvider serviceProvider) : IFlushHan using var scope = serviceProvider.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); + var now = SystemClock.Instance.GetCurrentInstant(); await db.BulkInsertAsync(items.Select(x => { - x.CreatedAt = SystemClock.Instance.GetCurrentInstant(); + x.CreatedAt = now; x.UpdatedAt = x.CreatedAt; return x; }), config => config.ConflictOption = ConflictOption.Ignore); diff --git a/DysonNetwork.Shared/Data/SoftDeleteExtension.cs b/DysonNetwork.Shared/Data/SoftDeleteExtension.cs index ad9de32..ac1f15a 100644 --- a/DysonNetwork.Shared/Data/SoftDeleteExtension.cs +++ b/DysonNetwork.Shared/Data/SoftDeleteExtension.cs @@ -26,7 +26,7 @@ public static class SoftDeleteExtension var method = typeof(SoftDeleteExtension) .GetMethod(nameof(SetSoftDeleteFilter), BindingFlags.NonPublic | BindingFlags.Static)! .MakeGenericMethod(entityType.ClrType); - method.Invoke(null, new object[] { modelBuilder }); + method.Invoke(null, [modelBuilder]); } } diff --git a/DysonNetwork.Shared/Models/CloudFile.cs b/DysonNetwork.Shared/Models/CloudFile.cs index d937f8a..7c92ace 100644 --- a/DysonNetwork.Shared/Models/CloudFile.cs +++ b/DysonNetwork.Shared/Models/CloudFile.cs @@ -129,7 +129,7 @@ public class SnCloudFileReference : ModelBase /// The protobuf message representation of this object public CloudFileReference ToProtoValue() { - return new Proto.CloudFileReference + return new CloudFileReference { Id = Id.ToString(), FileId = FileId,