Total vote count on topic list
-
@phenomlab I fixed the script in the above post, also made some changes to the plugin so it doesn't run the calculation on every page load. https://github.com/oplik0/nodebb-plugin-total-vote-count/pull/21
It will only calculate the total vote count if it is missing so any loads after that will use the cached value. Hopefully that improves performance.
-
@baris said in Total vote count on topic list:
I fixed the script in the above pos
Still doesn't work for me
throw new Error(`[[error:invalid-score, ${item[1]}]]`); ^ Error: [[error:invalid-score, NaN]] at /home/sudonix.org/nodebb/src/database/mongo/sorted/add.js:84:11 at Array.forEach (<anonymous>) at module.sortedSetAddBulk (/home/sudonix.org/nodebb/src/database/mongo/sorted/add.js:82:8) at Object.wrapperCallback [as sortedSetAddBulk] (/home/sudonix.org/nodebb/src/promisify.js:46:11) at batch.processSortedSet.batch (/home/sudonix.org/nodebb/vote.js:44:26) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async module.processSortedSet (/home/sudonix.org/nodebb/src/database/mongo/sorted.js:602:5) at async exports.processSortedSet (/home/sudonix.org/nodebb/src/batch.js:30:10) at async fixVotes (/home/sudonix.org/nodebb/vote.js:34:9) at async /home/sudonix.org/nodebb/vote.js:26:2
-
@phenomlab maybe try with below
/* eslint-disable no-await-in-loop */ /* globals require, console, process */ 'use strict'; const nconf = require('nconf'); nconf.file({ file: 'config.json', }); nconf.defaults({ base_dir: __dirname, views_dir: './build/public/templates', upload_path: 'public/uploads', }); const db = require('./src/database'); db.init(async (err) => { if (err) { console.log(`NodeBB could not connect to your database. Error: ${err.message}`); process.exit(); } await fixVotes(); console.log('done'); process.exit(); }); async function fixVotes() { const batch = require('./src/batch'); await batch.processSortedSet('topics:tid', async (tids) => { let topicData = await db.getObjectsFields( tids.map(tid => `topic:${tid}`), ['tid', 'cid', 'timestamp', 'upvotes', 'downvotes'] ); topicData = topicData.filter(t => t && t.cid); topicData.forEach((t) => { t.votes = parseInt(t.upvotes || 0, 10) - parseInt(t.downvotes || 0, 10); }); await db.sortedSetAddBulk( topicData.map(t => ([`cid:${t.cid}:tids:votes`, t.votes, t.tid])) ); await db.sortedSetAddBulk( topicData.map(t => ([`topic:votes`, t.votes, t.tid])) ); }, { batch: 500, }); }
-
@baris Just
/top
. For example, https://sudonix.org/topEDIT - having thought about it,
/top
doesn't display in vote order by default, but it doesn't display in view order either? -
@phenomlab I thought
/top
puts the topics in order according their vote number (number of votes of the first post)...@baris is this plugin affecting how
/top
behaves? or just how/popular
behaves?