Count totals using database instead of manually
This is way more efficient
This commit is contained in:
parent
faa53a3a7e
commit
921187a2aa
1 changed files with 3 additions and 8 deletions
|
@ -161,15 +161,10 @@ router.get('/', async (req, res) => {
|
|||
if (DEBUG) console.debug('Returning home page')
|
||||
|
||||
// count people
|
||||
// TODO: optimise to do using SQL only
|
||||
let total_people = 0
|
||||
let total_rupees = 0
|
||||
let result = await Pledge.fetchAll()
|
||||
let { total_people, total_rupees } = (await knex('pledges')
|
||||
.sum('amount as total_rupees')
|
||||
.count('* as total_people'))[0]
|
||||
|
||||
for (let pledge of result.models) {
|
||||
total_people += 1
|
||||
total_rupees += pledge.get('amount')
|
||||
}
|
||||
|
||||
twing.render('index.htm.twig', {
|
||||
'goal_rupees': Number(goalRupees).toLocaleString('en-IN'),
|
||||
|
|
Loading…
Reference in a new issue