nisnevich / discord-consensus-bot

A Discord bot for a consensus in decentralised organisations (e.g. DAO). Implements a lazy consensus and full consensus models.
MIT License
5 stars 4 forks source link

Refactor approve_grant_proposal to use sched instead of while #5

Closed nisnevich closed 1 year ago

nisnevich commented 1 year ago

Little but nice enchancement.

approve_grant_proposal uses inefficient code:

while grant_proposal.timer < GRANT_PROPOSAL_TIMER_SECONDS:
    await asyncio.sleep(GRANT_PROPOSAL_TIMER_SLEEP_SECONDS)
    grant_proposal.timer += GRANT_PROPOSAL_TIMER_SLEEP_SECONDS
    await db.commit()

Instead of storing timer value in DB, it's more efficient to store datetime object when the proposal was added, and so refactor approve_grant_proposal to just add GRANT_PROPOSAL_TIMER_SECONDS to it, and schedule grant() call with sched.scheduler.

nisnevich commented 1 year ago

But the method must exit whenever proposal is cancelled in on_raw_reaction_add.

nisnevich commented 1 year ago

LGTM, no plans to fix.