소스 검색

Fix issues with paginating based on descending rather than ascending time

sbkwgh 8 년 전
부모
커밋
5d30acb1e4
2개의 변경된 파일8개의 추가작업 그리고 3개의 파일을 삭제
  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