Skip to content

Commit

Permalink
Implement caching of poll items and signal based stale flag
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescowens committed Oct 30, 2023
1 parent 41fcb13 commit d5f476d
Show file tree
Hide file tree
Showing 5 changed files with 284 additions and 152 deletions.
21 changes: 21 additions & 0 deletions src/gridcoin/voting/registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,6 +1046,9 @@ void PollRegistry::AddVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(
*poll_ref->m_ptitle,
poll_ref->Votes().size());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}
}

Expand All @@ -1068,13 +1071,19 @@ void PollRegistry::AddVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(
return;
}
poll_ref->LinkVote(ctx.m_tx.GetHash());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}
}

void PollRegistry::DeletePoll(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(cs_main, PollRegistry::cs_poll_registry)
{
const auto payload = ctx->SharePayloadAs<PollPayload>();

int64_t poll_time = payload->m_poll.m_timestamp;

m_polls.erase(ToLower(payload->m_poll.m_title));

m_polls_by_txid.erase(ctx.m_tx.GetHash());
Expand All @@ -1085,6 +1094,10 @@ void PollRegistry::DeletePoll(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIR
payload->m_poll.m_title,
m_polls.size());

if (fQtActive) {
uiInterface.NewPollReceived(poll_time);;
}

}

void PollRegistry::DeleteVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIRED(cs_main, PollRegistry::cs_poll_registry)
Expand All @@ -1100,6 +1113,10 @@ void PollRegistry::DeleteVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIR
ctx.m_tx.GetHash().GetHex(),
*poll_ref->m_ptitle,
poll_ref->Votes().size());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}

return;
Expand All @@ -1114,6 +1131,10 @@ void PollRegistry::DeleteVote(const ContractContext& ctx) EXCLUSIVE_LOCKS_REQUIR

if (PollReference* poll_ref = TryBy(title)) {
poll_ref->UnlinkVote(ctx.m_tx.GetHash());

if (fQtActive && !poll_ref->Expired(GetAdjustedTime())) {
uiInterface.NewVoteReceived(poll_ref->Txid());
}
}
}

Expand Down
Loading

0 comments on commit d5f476d

Please sign in to comment.