Explorar o código

Fix issues with paginating based on descending rather than ascending time

sbkwgh %!s(int64=8) %!d(string=hai) anos
pai
achega
5d30acb1e4
Modificáronse 2 ficheiros con 8 adicións e 3 borrados
  1. 6 2
      lib/pagination.js
  2. 2 1
      routes/category.js

+ 6 - 2
lib/pagination.js

@@ -31,7 +31,7 @@ async function getNextIdDesc(Model, where, items) {
 }
 
 
-async function getNextCount (Model, items, limit, where) {
+async function getNextCount (Model, items, limit, where, desc) {
 	let lastItem
 
 	if(Array.isArray(items)) {
@@ -40,7 +40,11 @@ async function getNextCount (Model, items, limit, where) {
 		lastItem = items
 	}
 
-	where.id = { $gt: lastItem.id }
+	if(desc) {
+		where.id = { $lt: lastItem.id }
+	} else {
+		where.id = { $gt: lastItem.id }
+	}
 
 	let remaining = await Model.count({ where })
 

+ 2 - 1
routes/category.js

@@ -120,7 +120,8 @@ router.get('/:category', async (req, res) => {
 
 			resThreads.meta.nextThreadsCount = await pagination.getNextCount(
 				Thread, resThreads.Threads, limit,
-				user ? { userId: user.id } : {}
+				user ? { userId: user.id } : {},
+				true
 			)
 		} else {
 			resThreads.meta.nextURL = null