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')
|
if (DEBUG) console.debug('Returning home page')
|
||||||
|
|
||||||
// count people
|
// count people
|
||||||
// TODO: optimise to do using SQL only
|
let { total_people, total_rupees } = (await knex('pledges')
|
||||||
let total_people = 0
|
.sum('amount as total_rupees')
|
||||||
let total_rupees = 0
|
.count('* as total_people'))[0]
|
||||||
let result = await Pledge.fetchAll()
|
|
||||||
|
|
||||||
for (let pledge of result.models) {
|
|
||||||
total_people += 1
|
|
||||||
total_rupees += pledge.get('amount')
|
|
||||||
}
|
|
||||||
|
|
||||||
twing.render('index.htm.twig', {
|
twing.render('index.htm.twig', {
|
||||||
'goal_rupees': Number(goalRupees).toLocaleString('en-IN'),
|
'goal_rupees': Number(goalRupees).toLocaleString('en-IN'),
|
||||||
|
|
Loading…
Reference in a new issue