Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

중복순위 처리버그 수정 #68

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,7 @@ def fx_ranking_reward_csv() -> str:
11,124,0x74C6aFdB7405e8109D63521Fd8363f25fead0EcA,03b16b0096F8d5Df707c7cDCCf295a9A78182EA8,370,RUNESTONE_FENRIR1,0,2993
11,124,0x74C6aFdB7405e8109D63521Fd8363f25fead0EcA,03b16b0096F8d5Df707c7cDCCf295a9A78182EA8,105,RUNESTONE_FENRIR2,0,2993
11,124,0x74C6aFdB7405e8109D63521Fd8363f25fead0EcA,03b16b0096F8d5Df707c7cDCCf295a9A78182EA8,25,RUNESTONE_FENRIR3,0,2993
11,125,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,500000,CRYSTAL,18,2993
11,125,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,370,RUNESTONE_FENRIR1,0,2993
11,125,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,105,RUNESTONE_FENRIR2,0,2993
11,125,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,25,RUNESTONE_FENRIR3,0,2993"""
11,124,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,500000,CRYSTAL,18,2993
11,124,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,370,RUNESTONE_FENRIR1,0,2993
11,124,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,105,RUNESTONE_FENRIR2,0,2993
11,124,0xB7Bc6def28325784aF2Ce0f5BDbD01F619A11DB8,25B24f81Cd6da3433e337857Fcbdd8b0ae43DF69,25,RUNESTONE_FENRIR3,0,2993"""
13 changes: 6 additions & 7 deletions world_boss/app/raid.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,6 @@ def bulk_insert_transactions(
tx_ids[n] = tx_id
db.execute(insert(Transaction), tx_values)
raid_id = int(rows[0][0])
exist_rankings = [
r for r, in db.query(WorldBossReward.ranking).filter_by(raid_id=raid_id)
]
# avatar_address : list of world boss reward amount
world_boss_reward_amounts: dict[str, list[dict]] = {}
# raid_id,ranking,agent_address,avatar_address,amount,ticker,decimal_places,target_nonce
Expand All @@ -473,7 +470,7 @@ def bulk_insert_transactions(
nonce = int(row[7])

# get or create world_boss_reward
if ranking not in exist_rankings and not world_boss_rewards.get(avatar_address):
if not world_boss_rewards.get(avatar_address):
world_boss_reward = {
"raid_id": raid_id,
"ranking": ranking,
Expand All @@ -493,10 +490,12 @@ def bulk_insert_transactions(
world_boss_reward_amounts[avatar_address] = []
world_boss_reward_amounts[avatar_address].append(world_boss_reward_amount)
if world_boss_rewards:
db.execute(insert(WorldBossReward), world_boss_rewards.values())
result = db.query(WorldBossReward).filter_by(raid_id=raid_id)
result = db.execute(
insert(WorldBossReward).returning(WorldBossReward),
world_boss_rewards.values(),
)
values = []
for reward in result:
for (reward,) in result:
exist_tickers = [i.ticker for i in reward.amounts]
if world_boss_rewards.get(reward.avatar_address):
for amounts in world_boss_reward_amounts[reward.avatar_address]:
Expand Down
28 changes: 23 additions & 5 deletions world_boss/app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,12 @@ def check_season():
with TaskSessionLocal() as db:
raid_id = get_latest_raid_id(db)
total_count = data_provider_client.get_total_users_count(raid_id)
sync_count = offset = get_reward_count(db, raid_id)
sync_count = get_reward_count(db, raid_id)
offset = 0
# 최신 시즌 동기화 처리
if sync_count == total_count:
upload_tx_list(raid_id)
raid_id += 1
offset = 0
save_ranking_rewards(
raid_id=raid_id, payload_size=500, recipients_size=50, offset=offset
)
Expand All @@ -272,11 +272,27 @@ def save_ranking_rewards(
results: List[RankingRewardWithAgentDictionary] = []
time_stamp = get_next_month_last_day()
memo = "world boss ranking rewards by world boss signer"
target_avatar_addresses = []
with TaskSessionLocal() as db:
start_nonce = get_next_tx_nonce(db)
result = data_provider_client.get_ranking_rewards(
raid_id, NetworkType.MAIN, offset, payload_size
)
while True:
result = data_provider_client.get_ranking_rewards(
raid_id, NetworkType.MAIN, offset, payload_size
)
exist_avatar_addresses = [
i
for i, in db.query(WorldBossReward.avatar_address).filter_by(
raid_id=raid_id
)
]
Comment on lines +282 to +287
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이건 loop 밖에서 한번만 가져와도 될 것 같습니다. offset 을 딱히 사용하는 것도 아니고 full query 라서 반복할 필요가 없을 것 같네요.

avatar_addresses = [r["raider"]["address"] for r in result]
target_avatar_addresses = [
i for i in avatar_addresses if i not in exist_avatar_addresses
]
Comment on lines +289 to +291
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기왕에 list 만드느라 loop 도는거 exist_avatar_addressesavatar_addresses 를 set 으로 만들어서 avatar_addresses - exist_avatar_addresses 를 하면 빠르고 간편할 것 같습니다.

if len(target_avatar_addresses) > 0:
break
else:
offset += payload_size
Comment on lines +294 to +295
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

offset 을 계속 증가시키다가 DP 에서 가져오는 값이 없어지면 계속 else 를 타면서 무한 loop 에 빠질 수 있을 것 같습니다. DP 에서 가져올 게 더 없는 경우 탈출시키는 게 필요하지 않을까요?

rewards = update_agent_address(
result, raid_id, NetworkType.MAIN, offset, payload_size
)
Expand All @@ -288,6 +304,8 @@ def save_ranking_rewards(
raider: RaiderWithAgentDictionary = r["raider"]
ranking = raider["ranking"]
avatar_address = raider["address"]
if avatar_address not in target_avatar_addresses:
continue
reward_dict_list: List[RewardDictionary] = r["rewards"]
for reward_dict in reward_dict_list:
nonce = start_nonce + int(i / recipients_size)
Expand Down
Loading