fix: some fixes of multiple notification read (#8819)
* fix: limit multiple notification read * fix * fix
This commit is contained in:
		
							parent
							
								
									3a987b0006
								
							
						
					
					
						commit
						11a6bd890c
					
				
					 3 changed files with 18 additions and 2 deletions
				
			
		|  | @ -9,6 +9,8 @@ export async function readNotification( | ||||||
| 	userId: User['id'], | 	userId: User['id'], | ||||||
| 	notificationIds: Notification['id'][] | 	notificationIds: Notification['id'][] | ||||||
| ) { | ) { | ||||||
|  | 	if (notificationIds.length === 0) return; | ||||||
|  | 
 | ||||||
| 	// Update documents
 | 	// Update documents
 | ||||||
| 	await Notifications.update({ | 	await Notifications.update({ | ||||||
| 		id: In(notificationIds), | 		id: In(notificationIds), | ||||||
|  |  | ||||||
|  | @ -34,7 +34,11 @@ export const paramDef = { | ||||||
| 		{ | 		{ | ||||||
| 			type: 'object', | 			type: 'object', | ||||||
| 			properties: { | 			properties: { | ||||||
| 				notificationIds: { type: 'array', items: { type: 'string', format: 'misskey:id' } }, | 				notificationIds: { | ||||||
|  | 					type: 'array', | ||||||
|  | 					items: { type: 'string', format: 'misskey:id' }, | ||||||
|  | 					maxItems: 100, | ||||||
|  | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			required: ['notificationIds'], | 			required: ['notificationIds'], | ||||||
| 		}, | 		}, | ||||||
|  |  | ||||||
|  | @ -37,12 +37,22 @@ class SwNotificationReadManager { | ||||||
| 
 | 
 | ||||||
| 		account.queue.push(data.body.id as string); | 		account.queue.push(data.body.id as string); | ||||||
| 
 | 
 | ||||||
|  | 		if (account.queue.length >= 20) { | ||||||
|  | 			if (account.timeout) clearTimeout(account.timeout); | ||||||
|  | 			const notificationIds = account.queue; | ||||||
|  | 			account.queue = []; | ||||||
|  | 			await api('notifications/read', data.userId, { notificationIds }); | ||||||
|  | 			return; | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
| 		// 最後の呼び出しから200ms待ってまとめて処理する
 | 		// 最後の呼び出しから200ms待ってまとめて処理する
 | ||||||
| 		if (account.timeout) clearTimeout(account.timeout); | 		if (account.timeout) clearTimeout(account.timeout); | ||||||
| 		account.timeout = setTimeout(() => { | 		account.timeout = setTimeout(() => { | ||||||
| 			account.timeout = null; | 			account.timeout = null; | ||||||
| 
 | 
 | ||||||
| 			api('notifications/read', data.userId, { notificationIds: account.queue }); | 			const notificationIds = account.queue; | ||||||
|  | 			account.queue = []; | ||||||
|  | 			api('notifications/read', data.userId, { notificationIds }); | ||||||
| 		}, 200); | 		}, 200); | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue