-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from near-daos/develop
RC2
- Loading branch information
Showing
8 changed files
with
90 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { calcProposalVotePeriodEnd } from '@sputnik-v2/utils'; | ||
import PromisePool from '@supercharge/promise-pool'; | ||
import { ProposalService, ProposalVoteStatus } from '@sputnik-v2/proposal'; | ||
import { Migration } from '..'; | ||
|
||
@Injectable() | ||
export class ProposalVoteMigration implements Migration { | ||
private readonly logger = new Logger(ProposalVoteMigration.name); | ||
|
||
constructor(private readonly proposalService: ProposalService) {} | ||
|
||
public async migrate(): Promise<void> { | ||
this.logger.log('Starting Proposal Vote migration...'); | ||
|
||
this.logger.log('Collecting proposals...'); | ||
const proposals = await this.proposalService.find(); | ||
|
||
const currentTimestamp = new Date().getTime() * 1000 * 1000; // nanoseconds | ||
const migratedProposals = proposals.map((proposal) => { | ||
const votePeriodEnd = calcProposalVotePeriodEnd(proposal, proposal.dao); | ||
return { | ||
...proposal, | ||
votePeriodEnd, | ||
voteStatus: | ||
votePeriodEnd < currentTimestamp | ||
? ProposalVoteStatus.Active | ||
: ProposalVoteStatus.Expired, | ||
}; | ||
}); | ||
|
||
this.logger.log(`Updating migrated Proposals...`); | ||
const { results, errors: proposalErrors } = | ||
await PromisePool.withConcurrency(500) | ||
.for(migratedProposals) | ||
.process( | ||
async (proposal) => await this.proposalService.update(proposal), | ||
); | ||
|
||
this.logger.log( | ||
`Successfully updated Proposals: ${results.flat().length}. Errors: ${ | ||
proposalErrors.length | ||
}`, | ||
); | ||
this.logger.log('Proposal Vote migration finished.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters