apply changes

This commit is contained in:
qhy040404
2024-06-16 19:04:51 +08:00
parent 16ac52e71d
commit d05c196b7c
14 changed files with 133 additions and 143 deletions

View File

@@ -11,8 +11,8 @@ using Snap.Hutao.Model.Entity.Database;
namespace Snap.Hutao.Migrations
{
[DbContext(typeof(AppDbContext))]
[Migration("20240613144942_UserGameRoleProfilePicture")]
partial class UserGameRoleProfilePicture
[Migration("20240616104646_UidProfilePicture")]
partial class UidProfilePicture
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
@@ -469,6 +469,33 @@ namespace Snap.Hutao.Migrations
b.ToTable("spiral_abysses");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UidProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("uid_profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.User", b =>
{
b.Property<Guid>("InnerId")
@@ -518,33 +545,6 @@ namespace Snap.Hutao.Migrations
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UserGameRoleProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("LastUpdateTime")
.HasColumnType("TEXT");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")

View File

@@ -1,4 +1,5 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
@@ -6,13 +7,13 @@ using Microsoft.EntityFrameworkCore.Migrations;
namespace Snap.Hutao.Migrations
{
/// <inheritdoc />
public partial class UserGameRoleProfilePicture : Migration
public partial class UidProfilePicture : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "profile_pictures",
name: "uid_profile_pictures",
columns: table => new
{
InnerId = table.Column<Guid>(type: "TEXT", nullable: false),
@@ -20,11 +21,11 @@ namespace Snap.Hutao.Migrations
ProfilePictureId = table.Column<uint>(type: "INTEGER", nullable: false),
AvatarId = table.Column<uint>(type: "INTEGER", nullable: false),
CostumeId = table.Column<uint>(type: "INTEGER", nullable: false),
LastUpdateTime = table.Column<DateTimeOffset>(type: "TEXT", nullable: false)
RefreshTime = table.Column<DateTimeOffset>(type: "TEXT", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_profile_pictures", x => x.InnerId);
table.PrimaryKey("PK_uid_profile_pictures", x => x.InnerId);
});
}
@@ -32,7 +33,7 @@ namespace Snap.Hutao.Migrations
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "profile_pictures");
name: "uid_profile_pictures");
}
}
}

View File

@@ -466,6 +466,33 @@ namespace Snap.Hutao.Migrations
b.ToTable("spiral_abysses");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UidProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("RefreshTime")
.HasColumnType("TEXT");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("uid_profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.User", b =>
{
b.Property<Guid>("InnerId")
@@ -515,33 +542,6 @@ namespace Snap.Hutao.Migrations
b.ToTable("users");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.UserGameRoleProfilePicture", b =>
{
b.Property<Guid>("InnerId")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<uint>("AvatarId")
.HasColumnType("INTEGER");
b.Property<uint>("CostumeId")
.HasColumnType("INTEGER");
b.Property<DateTimeOffset>("LastUpdateTime")
.HasColumnType("TEXT");
b.Property<uint>("ProfilePictureId")
.HasColumnType("INTEGER");
b.Property<string>("Uid")
.IsRequired()
.HasColumnType("TEXT");
b.HasKey("InnerId");
b.ToTable("profile_pictures");
});
modelBuilder.Entity("Snap.Hutao.Model.Entity.Achievement", b =>
{
b.HasOne("Snap.Hutao.Model.Entity.AchievementArchive", "Archive")

View File

@@ -25,7 +25,7 @@ internal sealed class AppDbContext : DbContext
public AppDbContext(DbContextOptions<AppDbContext> options)
: base(options)
{
logger = this.GetService<ILogger<AppDbContext>>();
//logger = this.GetService<ILogger<AppDbContext>>();
logger?.LogColorizedInformation("{Name}[{Id}] {Action}", nameof(AppDbContext), (ContextId, ConsoleColor.DarkCyan), ("created", ConsoleColor.Green));
}
@@ -65,7 +65,7 @@ internal sealed class AppDbContext : DbContext
public DbSet<SpiralAbyssEntry> SpiralAbysses { get; set; } = default!;
public DbSet<UserGameRoleProfilePicture> UserGameRoleProfilePictures { get; set; } = default!;
public DbSet<UidProfilePicture> UidProfilePictures { get; set; } = default!;
public static AppDbContext Create(IServiceProvider serviceProvider, string sqlConnectionString)
{

View File

@@ -9,9 +9,9 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Snap.Hutao.Model.Entity;
[Table("profile_pictures")]
[Table("uid_profile_pictures")]
[SuppressMessage("", "SH002")]
internal sealed class UserGameRoleProfilePicture : IMappingFrom<UserGameRoleProfilePicture, PlayerUid, ProfilePicture>
internal sealed class UidProfilePicture : IMappingFrom<UidProfilePicture, PlayerUid, ProfilePicture>
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
@@ -25,9 +25,9 @@ internal sealed class UserGameRoleProfilePicture : IMappingFrom<UserGameRoleProf
public uint CostumeId { get; set; }
public DateTimeOffset LastUpdateTime { get; set; }
public DateTimeOffset RefreshTime { get; set; }
public static UserGameRoleProfilePicture From(PlayerUid uid, ProfilePicture profilePicture)
public static UidProfilePicture From(PlayerUid uid, ProfilePicture profilePicture)
{
return new()
{
@@ -35,7 +35,7 @@ internal sealed class UserGameRoleProfilePicture : IMappingFrom<UserGameRoleProf
ProfilePictureId = profilePicture.ProfilePictureId,
AvatarId = profilePicture.AvatarId,
CostumeId = profilePicture.CostumeId,
LastUpdateTime = DateTimeOffset.Now,
RefreshTime = DateTimeOffset.Now,
};
}
}

View File

@@ -0,0 +1,16 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.User;
internal interface IUidProfilePictureDbService : IAppDbService<UidProfilePicture>
{
ValueTask<UidProfilePicture?> SingleUidProfilePictureOrDefaultByUidAsync(string uid, CancellationToken token = default);
ValueTask UpdateUidProfilePictureAsync(UidProfilePicture profilePicture, CancellationToken token = default);
ValueTask DeleteUidProfilePictureByUidAsync(string uid, CancellationToken token = default);
}

View File

@@ -1,18 +0,0 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.User;
internal interface IUserGameRoleDbService : IAppDbService<UserGameRoleProfilePicture>
{
ValueTask<bool> ContainsUidAsync(string uid, CancellationToken token = default);
ValueTask<UserGameRoleProfilePicture> GetUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default);
ValueTask UpdateUserGameRoleProfilePictureAsync(UserGameRoleProfilePicture profilePicture, CancellationToken token = default);
ValueTask DeleteUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default);
}

View File

@@ -11,5 +11,5 @@ internal interface IUserInitializationService
ValueTask<ViewModel.User.User> ResumeUserAsync(Model.Entity.User inner, CancellationToken token = default(CancellationToken));
ValueTask RefreshUserGameRolesProfilePictureAsync(UserGameRole userGameRole, CancellationToken token = default);
ValueTask RefreshUidProfilePictureAsync(UserGameRole userGameRole, CancellationToken token = default);
}

View File

@@ -54,5 +54,5 @@ internal interface IUserService
/// <returns>任务</returns>
ValueTask RemoveUserAsync(BindingUser user);
ValueTask RefreshUserGameRoleProfilePictureAsync(UserGameRole userGameRole);
ValueTask RefreshUidProfilePictureAsync(UserGameRole userGameRole);
}

View File

@@ -0,0 +1,32 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.EntityFrameworkCore;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.User;
[ConstructorGenerated]
[Injection(InjectAs.Singleton, typeof(IUidProfilePictureDbService))]
internal sealed partial class UidProfilePictureDbService : IUidProfilePictureDbService
{
private readonly IServiceProvider serviceProvider;
public IServiceProvider ServiceProvider { get => serviceProvider; }
public ValueTask<UidProfilePicture?> SingleUidProfilePictureOrDefaultByUidAsync(string uid, CancellationToken token = default)
{
return this.QueryAsync(query => query.SingleOrDefaultAsync(n => n.Uid == uid));
}
public async ValueTask UpdateUidProfilePictureAsync(UidProfilePicture profilePicture, CancellationToken token = default)
{
await this.UpdateAsync(profilePicture, token).ConfigureAwait(false);
}
public async ValueTask DeleteUidProfilePictureByUidAsync(string uid, CancellationToken token = default)
{
await this.DeleteAsync(profilePicture => profilePicture.Uid == uid, token).ConfigureAwait(false);
}
}

View File

@@ -1,37 +0,0 @@
// Copyright (c) DGP Studio. All rights reserved.
// Licensed under the MIT license.
using Microsoft.EntityFrameworkCore;
using Snap.Hutao.Model.Entity;
using Snap.Hutao.Service.Abstraction;
namespace Snap.Hutao.Service.User;
[ConstructorGenerated]
[Injection(InjectAs.Singleton, typeof(IUserGameRoleDbService))]
internal sealed partial class UserGameRoleDbService : IUserGameRoleDbService
{
private readonly IServiceProvider serviceProvider;
public IServiceProvider ServiceProvider { get => serviceProvider; }
public ValueTask<bool> ContainsUidAsync(string uid, CancellationToken token = default)
{
return this.QueryAsync(query => query.AnyAsync(n => n.Uid == uid));
}
public ValueTask<UserGameRoleProfilePicture> GetUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default)
{
return this.QueryAsync(query => query.FirstAsync(n => n.Uid == uid));
}
public async ValueTask UpdateUserGameRoleProfilePictureAsync(UserGameRoleProfilePicture profilePicture, CancellationToken token = default)
{
await this.UpdateAsync(profilePicture, token).ConfigureAwait(false);
}
public async ValueTask DeleteUserGameRoleProfilePictureByUidAsync(string uid, CancellationToken token = default)
{
await this.DeleteAsync(profilePicture => profilePicture.Uid == uid, token).ConfigureAwait(false);
}
}

View File

@@ -23,7 +23,7 @@ namespace Snap.Hutao.Service.User;
internal sealed partial class UserInitializationService : IUserInitializationService
{
private readonly IUserFingerprintService userFingerprintService;
private readonly IUserGameRoleDbService userGameRoleDbService;
private readonly IUidProfilePictureDbService uidProfilePictureDbService;
private readonly IServiceProvider serviceProvider;
public async ValueTask<ViewModel.User.User> ResumeUserAsync(Model.Entity.User inner, CancellationToken token = default)
@@ -63,7 +63,7 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
}
}
public async ValueTask RefreshUserGameRolesProfilePictureAsync(UserGameRole userGameRole, CancellationToken token = default)
public async ValueTask RefreshUidProfilePictureAsync(UserGameRole userGameRole, CancellationToken token = default)
{
EnkaResponse? enkaResponse;
using (IServiceScope scope = serviceProvider.CreateScope())
@@ -78,12 +78,12 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
if (enkaResponse is { PlayerInfo: { } playerInfo })
{
UserGameRoleProfilePicture profilePicture = UserGameRoleProfilePicture.From(userGameRole, playerInfo.ProfilePicture);
UidProfilePicture profilePicture = UidProfilePicture.From(userGameRole, playerInfo.ProfilePicture);
await userGameRoleDbService.DeleteUserGameRoleProfilePictureByUidAsync(userGameRole.GameUid, token).ConfigureAwait(false);
await userGameRoleDbService.UpdateUserGameRoleProfilePictureAsync(profilePicture, token).ConfigureAwait(false);
await uidProfilePictureDbService.DeleteUidProfilePictureByUidAsync(userGameRole.GameUid, token).ConfigureAwait(false);
await uidProfilePictureDbService.UpdateUidProfilePictureAsync(profilePicture, token).ConfigureAwait(false);
await SetUserGameRolesProfilePictureCoreAsync(userGameRole, profilePicture, token).ConfigureAwait(false);
await SetUserGameRoleProfilePictureCoreAsync(userGameRole, profilePicture, token).ConfigureAwait(false);
}
}
@@ -255,25 +255,21 @@ internal sealed partial class UserInitializationService : IUserInitializationSer
{
foreach (UserGameRole userGameRole in user.UserGameRoles)
{
if (await userGameRoleDbService.ContainsUidAsync(userGameRole.GameUid, token).ConfigureAwait(false))
if (await uidProfilePictureDbService.SingleUidProfilePictureOrDefaultByUidAsync(userGameRole.GameUid, token).ConfigureAwait(false) is { } profilePicture)
{
UserGameRoleProfilePicture savedProfilePicture = await userGameRoleDbService
.GetUserGameRoleProfilePictureByUidAsync(userGameRole.GameUid, token)
.ConfigureAwait(false);
if (await SetUserGameRolesProfilePictureCoreAsync(userGameRole, savedProfilePicture, token).ConfigureAwait(false))
if (await SetUserGameRoleProfilePictureCoreAsync(userGameRole, profilePicture, token).ConfigureAwait(false))
{
continue;
}
}
await RefreshUserGameRolesProfilePictureAsync(userGameRole, token).ConfigureAwait(false);
await RefreshUidProfilePictureAsync(userGameRole, token).ConfigureAwait(false);
}
}
private async ValueTask<bool> SetUserGameRolesProfilePictureCoreAsync(UserGameRole userGameRole, UserGameRoleProfilePicture profilePicture, CancellationToken token = default)
private async ValueTask<bool> SetUserGameRoleProfilePictureCoreAsync(UserGameRole userGameRole, UidProfilePicture profilePicture, CancellationToken token = default)
{
if (profilePicture.LastUpdateTime.AddDays(15) < DateTimeOffset.Now)
if (profilePicture.RefreshTime.AddDays(15) < DateTimeOffset.Now)
{
return false;
}

View File

@@ -123,8 +123,8 @@ internal sealed partial class UserService : IUserService, IUserServiceUnsafe
return true;
}
public async ValueTask RefreshUserGameRoleProfilePictureAsync(UserGameRole userGameRole)
public async ValueTask RefreshUidProfilePictureAsync(UserGameRole userGameRole)
{
await userInitializationService.RefreshUserGameRolesProfilePictureAsync(userGameRole).ConfigureAwait(false);
await userInitializationService.RefreshUidProfilePictureAsync(userGameRole).ConfigureAwait(false);
}
}

View File

@@ -302,6 +302,6 @@ internal sealed partial class UserViewModel : ObservableObject
[Command("RefreshUserGameRoleProfilePictureCommand")]
private void RefreshUserGameRoleProfilePicture(UserGameRole userGameRole)
{
userService.RefreshUserGameRoleProfilePictureAsync(userGameRole).SafeForget();
userService.RefreshUidProfilePictureAsync(userGameRole).SafeForget();
}
}