mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 02:55:58 +01:00 
			
		
		
		
	feat: add TTL cache for Actors.assert
This commit is contained in:
		| @@ -5,6 +5,9 @@ const winston = require('winston'); | |||||||
| const db = require('../database'); | const db = require('../database'); | ||||||
| const user = require('../user'); | const user = require('../user'); | ||||||
| const utils = require('../utils'); | const utils = require('../utils'); | ||||||
|  | const TTLCache = require('../cache/ttl'); | ||||||
|  |  | ||||||
|  | const failedWebfingerCache = TTLCache({ ttl: 1000 * 60 * 10 }); // 10 minutes | ||||||
|  |  | ||||||
| const activitypub = module.parent.exports; | const activitypub = module.parent.exports; | ||||||
|  |  | ||||||
| @@ -17,14 +20,17 @@ Actors.assert = async (ids, options = {}) => { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	// Filter out uids if passed in | 	// Filter out uids if passed in | ||||||
| 	ids = ids.filter(id => !utils.isNumber(id)); | 	ids = ids.filter(id => !utils.isNumber(id) && !failedWebfingerCache.has(id)); | ||||||
|  |  | ||||||
| 	// Translate webfinger handles to uris | 	// Translate webfinger handles to uris | ||||||
| 	ids = await Promise.all(ids.map(async (id) => { | 	ids = await Promise.all(ids.map(async (id) => { | ||||||
|  | 		const originalId = id; | ||||||
| 		if (id.includes('@')) { | 		if (id.includes('@')) { | ||||||
| 			({ actorUri: id } = await activitypub.helpers.query(id)); | 			({ actorUri: id } = await activitypub.helpers.query(id)); | ||||||
| 		} | 		} | ||||||
|  | 		if (!id) { | ||||||
|  | 			failedWebfingerCache.set(originalId, true); | ||||||
|  | 		} | ||||||
| 		return id; | 		return id; | ||||||
| 	})); | 	})); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user