mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	feat: add failing test for pagination (#7924)
* feat: add failing test for pagination * feat: test * fix: redis tests * refactor: remove logs
This commit is contained in:
		
				
					committed by
					
						 GitHub
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							969c5d4a2b
						
					
				
				
					commit
					22b02f1407
				
			| @@ -82,10 +82,10 @@ module.exports = function (module) { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		let result = []; | 		let result = []; | ||||||
| 		async function doQuery(_key, fields) { | 		async function doQuery(_key, fields, skip, limit) { | ||||||
| 			return await module.client.collection('objects').find({ ...query, ...{ _key: _key } }, { projection: fields }) | 			return await module.client.collection('objects').find({ ...query, ...{ _key: _key } }, { projection: fields }) | ||||||
| 				.sort({ score: sort }) | 				.sort({ score: sort }) | ||||||
| 				.skip(start) | 				.skip(skip) | ||||||
| 				.limit(limit) | 				.limit(limit) | ||||||
| 				.toArray(); | 				.toArray(); | ||||||
| 		} | 		} | ||||||
| @@ -93,11 +93,15 @@ module.exports = function (module) { | |||||||
| 		if (isArray && key.length > 100) { | 		if (isArray && key.length > 100) { | ||||||
| 			const batches = []; | 			const batches = []; | ||||||
| 			const batch = require('../../batch'); | 			const batch = require('../../batch'); | ||||||
| 			await batch.processArray(key, async currentBatch => batches.push(currentBatch), { batch: 100 }); | 			const batchSize = Math.ceil(key.length / Math.ceil(key.length / 100)); | ||||||
| 			const batchData = await Promise.all(batches.map(batch => doQuery({ $in: batch }, { _id: 0, _key: 0 }))); | 			await batch.processArray(key, async currentBatch => batches.push(currentBatch), { batch: batchSize }); | ||||||
| 			result = dbHelpers.mergeBatch(batchData, start, stop, sort); | 			const batchData = await Promise.all(batches.map(batch => doQuery({ $in: batch }, { _id: 0, _key: 0 }, 0, stop + 1))); | ||||||
|  | 			result = dbHelpers.mergeBatch(batchData, 0, stop, sort); | ||||||
|  | 			if (start > 0) { | ||||||
|  | 				result = result.slice(start, stop !== -1 ? stop + 1 : undefined); | ||||||
|  | 			} | ||||||
| 		} else { | 		} else { | ||||||
| 			result = await doQuery(query._key, fields); | 			result = await doQuery(query._key, fields, start, limit); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (reverse) { | 		if (reverse) { | ||||||
|   | |||||||
| @@ -32,13 +32,16 @@ module.exports = function (module) { | |||||||
| 				return []; | 				return []; | ||||||
| 			} | 			} | ||||||
| 			const batch = module.client.batch(); | 			const batch = module.client.batch(); | ||||||
| 			key.forEach(key => batch[method]([key, start, stop, 'WITHSCORES'])); | 			key.forEach(key => batch[method]([key, 0, stop, 'WITHSCORES'])); | ||||||
| 			const data = await helpers.execBatch(batch); | 			const data = await helpers.execBatch(batch); | ||||||
|  |  | ||||||
| 			const batchData = data.map(setData => helpers.zsetToObjectArray(setData)); | 			const batchData = data.map(setData => helpers.zsetToObjectArray(setData)); | ||||||
|  |  | ||||||
| 			let objects = dbHelpers.mergeBatch(batchData, start, stop, method === 'zrange' ? 1 : -1); | 			let objects = dbHelpers.mergeBatch(batchData, 0, stop, method === 'zrange' ? 1 : -1); | ||||||
|  |  | ||||||
|  | 			if (start > 0) { | ||||||
|  | 				objects = objects.slice(start, stop !== -1 ? stop + 1 : undefined); | ||||||
|  | 			} | ||||||
| 			if (!withScores) { | 			if (!withScores) { | ||||||
| 				objects = objects.map(item => item.value); | 				objects = objects.map(item => item.value); | ||||||
| 			} | 			} | ||||||
|   | |||||||
| @@ -279,6 +279,9 @@ describe('Sorted Set methods', function () { | |||||||
|  |  | ||||||
| 			data = await db.getSortedSetRevRange(keys, 0, -1); | 			data = await db.getSortedSetRevRange(keys, 0, -1); | ||||||
| 			assert.equal(data.length, 40000); | 			assert.equal(data.length, 40000); | ||||||
|  |  | ||||||
|  | 			data = await db.getSortedSetRange(keys, 9998, 10002); | ||||||
|  | 			assert.deepStrictEqual(data, ['9998', '9999', '10000', '10001', '10002']); | ||||||
| 		}); | 		}); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user