mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-29 18:16:17 +01:00 
			
		
		
		
	fix: extra orderedItems property in generated paginated OrderedCollection, #13153
				
					
				
			This commit is contained in:
		| @@ -451,6 +451,8 @@ Helpers.makeSet = (object, properties) => new Set(properties.reduce((memo, prope | |||||||
| Helpers.generateCollection = async ({ set, method, count, page, perPage, url }) => { | Helpers.generateCollection = async ({ set, method, count, page, perPage, url }) => { | ||||||
| 	if (!method) { | 	if (!method) { | ||||||
| 		method = db.getSortedSetRange.bind(null, set); | 		method = db.getSortedSetRange.bind(null, set); | ||||||
|  | 	} else if (set) { | ||||||
|  | 		method = method.bind(null, set); | ||||||
| 	} | 	} | ||||||
| 	count = count || await db.sortedSetCard(set); | 	count = count || await db.sortedSetCard(set); | ||||||
| 	const pageCount = Math.max(1, Math.ceil(count / perPage)); | 	const pageCount = Math.max(1, Math.ceil(count / perPage)); | ||||||
| @@ -486,8 +488,6 @@ Helpers.generateCollection = async ({ set, method, count, page, perPage, url }) | |||||||
| 			object.next = page < pageCount ? `${url}?page=${page + 1}` : null; | 			object.next = page < pageCount ? `${url}?page=${page + 1}` : null; | ||||||
| 			object.prev = page > 1 ? `${url}?page=${page - 1}` : null; | 			object.prev = page > 1 ? `${url}?page=${page - 1}` : null; | ||||||
| 		} | 		} | ||||||
| 	} else { |  | ||||||
| 		object.orderedItems = []; |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (paginate) { | 	if (paginate) { | ||||||
|   | |||||||
| @@ -156,7 +156,7 @@ Actors.topic = async function (req, res, next) { | |||||||
| 		res.set('ETag', digest); | 		res.set('ETag', digest); | ||||||
|  |  | ||||||
| 		// Convert pids to urls | 		// Convert pids to urls | ||||||
| 		if (page || collection.totalItems < meta.config.postsPerPage) { | 		if (page || collection.totalItems < perPage) { | ||||||
| 			collection.orderedItems = collection.orderedItems || []; | 			collection.orderedItems = collection.orderedItems || []; | ||||||
| 			if (!page || page === 1) { // add OP to collection | 			if (!page || page === 1) { // add OP to collection | ||||||
| 				collection.orderedItems.unshift(mainPid); | 				collection.orderedItems.unshift(mainPid); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user