Skip to content

Commit

Permalink
Add LatestBattleBlockIndex on log
Browse files Browse the repository at this point in the history
  • Loading branch information
ipdae committed Dec 19, 2024
1 parent ac08860 commit d59091a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 3 additions & 3 deletions ArenaService/ArenaService/ArenaWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ public async Task PrepareArenaParticipants()
// 전체목록의 랭킹 순서 처리
var avatarAddrAndScoresWithRank = AvatarAddrAndScoresWithRank(avatarAddrAndScores);
// 전체목록의 ArenaParticipant 업데이트
var result = await _rpcClient.GetArenaParticipants(tip, championshipId, round, updatedAddressAndScores.Select(i => i.AvatarAddr).ToList(), avatarAddrAndScoresWithRank, prevArenaParticipants, cancellationToken);
var tuple = await _rpcClient.GetArenaParticipants(tip, championshipId, round, updatedAddressAndScores.Select(i => i.AvatarAddr).ToList(), avatarAddrAndScoresWithRank, prevArenaParticipants, cancellationToken);
// 캐시 업데이트
await _service.SetArenaParticipantsAsync(cacheKey, result, expiry);
await _service.SetArenaParticipantsAsync(cacheKey, tuple.Item1, expiry);
await _service.SetSeasonAsync(cacheKey, expiry);
await _service.SetAvatarAddrAndScores(scoreCacheKey, avatarAddrAndScores, expiry);
sw.Stop();
_logger.LogInformation("[ArenaParticipantsWorker]Set Arena Cache[{CacheKey}] on {BlockIndex}: {Elapsed}", cacheKey, blockIndex, sw.Elapsed);
_logger.LogInformation("[ArenaParticipantsWorker]Set Arena Cache[{CacheKey}] on {BlockIndex}/{LatestBattleBlockIndex}: {Elapsed}", cacheKey, blockIndex, tuple.Item2, sw.Elapsed);
}


Expand Down
9 changes: 6 additions & 3 deletions ArenaService/ArenaService/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ public async Task<List<AvatarAddressAndScore>> GetAvatarAddrAndScores(Block bloc
/// <param name="avatarAddrAndScoresWithRank">The list of avatar addresses with their scores and ranks.</param>
/// <param name="prevArenaParticipants">The list of previous synced arena participants. if the score has not changed, <see cref="ArenaParticipantStruct"/> is reused.</param>
/// <param name="cancellationToken"></param>
/// <returns><see cref="Task"/>A list of arena participants.</returns>
public async Task<List<ArenaParticipantStruct>> GetArenaParticipants(Block block, int championshipId, int round, List<Address> avatarAddrList,
/// <returns><see cref="Task"/>A list of arena participants and latest RankingBattle executed block index.</returns>
public async Task<(List<ArenaParticipantStruct>, long)> GetArenaParticipants(Block block, int championshipId, int round, List<Address> avatarAddrList,
List<ArenaScoreAndRank> avatarAddrAndScoresWithRank, List<ArenaParticipantStruct> prevArenaParticipants,
CancellationToken cancellationToken)
{
Expand All @@ -297,6 +297,9 @@ public async Task<List<ArenaParticipantStruct>> GetArenaParticipants(Block block
}

var arenaParticipantStates = await GetArenaParticipantStates(block, championshipId, round, avatarAddrList, cancellationToken);
var latestBlockIndex = arenaParticipantStates.Count > 0
? arenaParticipantStates.Values.Max(i => i.LastBattleBlockIndex)
: 0L;
var tasks = avatarAddrAndScoresWithRank.Select(async tuple =>
{
if (cancellationToken.IsCancellationRequested)
Expand Down Expand Up @@ -336,7 +339,7 @@ public async Task<List<ArenaParticipantStruct>> GetArenaParticipants(Block block
);
}).ToList();
var result = await Task.WhenAll(tasks);
return result.ToList();
return (result.ToList(), latestBlockIndex);
}

/// <summary>
Expand Down

0 comments on commit d59091a

Please sign in to comment.