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

fix: getBadges query #1250

Merged
merged 1 commit into from
Sep 7, 2023
Merged
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
5 changes: 4 additions & 1 deletion src/clients/OtterspaceSubgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ query Badges($raft_id: String!, $address: Bytes!, $first: Int!, $skip: Int!) {
}`

const BADGE_SPEC_OWNERS_QUERY = `
query Badges($badgeCid: String!) {
query Badges($badgeCid: String!, $skip: Int!, $first: Int!) {
badges: badges(
where: {spec: $badgeCid}
orderBy: id
first: $first
skip: $skip
){
id
owner {
Expand Down
30 changes: 20 additions & 10 deletions src/services/BadgesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,26 +117,36 @@ export class BadgesService {
landOwnerAddresses
)

const outcomes: AirdropOutcome[] = []
const batches = splitArray([...eligibleUsers, ...usersWithBadgesToReinstate], 50)

for (const batch of batches) {
const outcome = await BadgesService.giveBadgeToUsers(LAND_OWNER_BADGE_SPEC_CID, batch)
outcomes.push(outcome)
const airdropOutcomes: AirdropOutcome[] = []
const airdropBatches = splitArray(eligibleUsers, 50)
for (const batch of airdropBatches) {
const outcome = await airdropWithRetry(LAND_OWNER_BADGE_SPEC_CID, batch)
airdropOutcomes.push(outcome)
}

const failedOutcomes = outcomes.filter(
const reinstateResults = await BadgesService.reinstateBadge(LAND_OWNER_BADGE_SPEC_CID, usersWithBadgesToReinstate)

const failedAirdropOutcomes = airdropOutcomes.filter(
({ status, error }) =>
status === AirdropJobStatus.FAILED &&
error !== ErrorReason.NoUserWithoutBadge &&
error !== ErrorReason.NoUserHasVoted
)
if (failedOutcomes.length > 0) {
console.error('Unable to give LandOwner badges', failedOutcomes)
if (failedAirdropOutcomes.length > 0) {
console.error('Unable to give LandOwner badges', failedAirdropOutcomes)

ErrorService.report('Unable to give LandOwner badges', {
category: ErrorCategory.Badges,
failedOutcomes,
failedAirdropOutcomes,
})
}

const failedReinstatements = reinstateResults.filter((result) => result.status === ActionStatus.Failed)
if (failedReinstatements.length > 0) {
console.error('Unable to reinstate LandOwner badges', failedReinstatements)
ErrorService.report('Unable to reinstate LandOwner badges', {
category: ErrorCategory.Badges,
failedReinstatements,
})
}

Expand Down