From 8855109674c5461211b91ca596557b6194d15ed0 Mon Sep 17 00:00:00 2001 From: Yang Chun Ung Date: Fri, 31 May 2024 13:59:10 +0900 Subject: [PATCH] Log result --- .../Queries/NineChroniclesSummaryMutation.cs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/NineChronicles.DataProvider/Queries/NineChroniclesSummaryMutation.cs b/NineChronicles.DataProvider/Queries/NineChroniclesSummaryMutation.cs index 3d9b9ac9..f1313966 100644 --- a/NineChronicles.DataProvider/Queries/NineChroniclesSummaryMutation.cs +++ b/NineChronicles.DataProvider/Queries/NineChroniclesSummaryMutation.cs @@ -3,6 +3,7 @@ namespace NineChronicles.DataProvider.Queries using System; using System.Collections.Generic; using System.Linq; + using System.Text; using GraphQL; using GraphQL.Types; using Libplanet.Crypto; @@ -20,7 +21,7 @@ public NineChroniclesSummaryMutation(MySqlStore store, StateContext stateContext Store = store; StateContext = stateContext; - Field>( + Field>( name: "migrateMoca", arguments: new QueryArguments( new QueryArgument>> @@ -34,8 +35,15 @@ public NineChroniclesSummaryMutation(MySqlStore store, StateContext stateContext var mocas = Store.GetMocasBySigner(signers); var collectionSheet = StateContext.WorldState.GetSheet(); var blockIndex = Store.GetTip(); - MigrateMoca(mocas, Store, collectionSheet, blockIndex, StateContext); - return true; + var result = MigrateMoca(mocas, Store, collectionSheet, blockIndex, StateContext); + StringBuilder sb = new StringBuilder(string.Empty); + foreach (var kv in result) + { + var log = $"{kv.Key},{kv.Value.Item1},{kv.Value.Item2}\n"; + sb.Append(log); + } + + return sb; } ); } @@ -44,8 +52,9 @@ public NineChroniclesSummaryMutation(MySqlStore store, StateContext stateContext private StateContext StateContext { get; } - public static void MigrateMoca(ICollection mocas, MySqlStore mySqlStore, CollectionSheet collectionSheet, long blockIndex, StateContext stateContext) + public static Dictionary MigrateMoca(ICollection mocas, MySqlStore mySqlStore, CollectionSheet collectionSheet, long blockIndex, StateContext stateContext) { + var result = new Dictionary(); foreach (var moca in mocas) { var avatars = mySqlStore.GetAvatarsFromSigner(moca.Signer); @@ -57,7 +66,8 @@ public static void MigrateMoca(ICollection mocas, MySqlSto var collectionState = stateContext.WorldState.GetCollectionState(new Address(avatar.Address!)); var existIds = avatar.ActivateCollections.Select(i => i.CollectionId).ToList(); var targetIds = collectionState.Ids.Except(existIds).ToList(); - Log.Information("[MigrateMoca] migration targets: {Address}, {ExistIds}, {TargetIds}", avatar.Address, string.Join(",", existIds), string.Join(",", targetIds)); + Log.Information("[MigrateMoca] migration targets: {Address}, [{ExistIds}]/[{TargetIds}]", avatar.Address, string.Join(",", existIds), string.Join(",", targetIds)); + var previous = avatar.ActivateCollections.Count; foreach (var collectionId in targetIds) { var row = collectionSheet[collectionId]; @@ -87,7 +97,10 @@ public static void MigrateMoca(ICollection mocas, MySqlSto if (targetIds.Any()) { mySqlStore.UpdateAvatar(avatar); + Log.Information("[MigrateMoca] Update Avatar: {Address}, [{Previous}]/[{New}]", avatar.Address, previous, avatar.ActivateCollections.Count); } + + result[avatar.Address!] = (previous, avatar.ActivateCollections.Count); } catch (Exception e) { @@ -102,6 +115,8 @@ public static void MigrateMoca(ICollection mocas, MySqlSto mySqlStore.UpdateMoca(moca.Signer); } } + + return result; } } }