From 81b8263f0036dce89bb58d03d17ec95afac49dd2 Mon Sep 17 00:00:00 2001 From: Alex Yocom-Piatt Date: Thu, 23 Jul 2020 11:42:52 -0400 Subject: [PATCH] only batch proposals once --- politeiawww/invoices.go | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/politeiawww/invoices.go b/politeiawww/invoices.go index 41b3957e3..c1396d4b3 100644 --- a/politeiawww/invoices.go +++ b/politeiawww/invoices.go @@ -1803,6 +1803,24 @@ func (p *politeiawww) processProposalBillingSummary(pbs cms.ProposalBillingSumma approvedProposals := tvr.Approved + var bpr www.BatchProposalsReply + if len(approvedProposals) > 0 { + // Go fetch proposal information to get name/title. + bp := &www.BatchProposals{ + Tokens: approvedProposals, + } + + data, err := p.makeProposalsRequest(http.MethodPost, www.RouteBatchProposals, bp) + if err != nil { + return nil, err + } + + err = json.Unmarshal(data, &bpr) + if err != nil { + return nil, err + } + } + count := pbs.Count if count > cms.ProposalBillingListPageSize { count = cms.ProposalBillingListPageSize @@ -1841,22 +1859,13 @@ func (p *politeiawww) processProposalBillingSummary(pbs cms.ProposalBillingSumma } totalSpent += int64(payout.Total) } - // Go fetch proposal information to get name/title. - bp := &www.BatchProposals{ - Tokens: []string{prop}, - } - - data, err := p.makeProposalsRequest(http.MethodPost, www.RouteBatchProposals, bp) - if err != nil { - return nil, err - } - - var bpr www.BatchProposalsReply - err = json.Unmarshal(data, &bpr) - if err != nil { - return nil, err + // Look across approved proposals batch reply for proposal name. + for _, propDetails := range bpr.Proposals { + if propDetails.CensorshipRecord.Token == prop { + spendingSummary.Title = propDetails.Name + break + } } - spendingSummary.Title = bpr.Proposals[0].Name spendingSummary.TotalBilled = totalSpent spendingSummaries = append(spendingSummaries, spendingSummary) }