improve performance
This commit is contained in:
		
							parent
							
								
									746fac0dfe
								
							
						
					
					
						commit
						d5aee2ea58
					
				
					 14 changed files with 88 additions and 44 deletions
				
			
		|  | @ -9,6 +9,7 @@ import { QueueService } from '@/core/QueueService.js'; | |||
| import { CreateSystemUserService } from '@/core/CreateSystemUserService.js'; | ||||
| import { ApRendererService } from '@/core/remote/activitypub/ApRendererService.js'; | ||||
| import { DI } from '@/di-symbols.js'; | ||||
| import { deepClone } from '@/misc/clone.js'; | ||||
| 
 | ||||
| const ACTOR_USERNAME = 'relay.actor' as const; | ||||
| 
 | ||||
|  | @ -105,7 +106,7 @@ export class RelayService { | |||
| 		})); | ||||
| 		if (relays.length === 0) return; | ||||
| 	 | ||||
| 		const copy = structuredClone(activity); | ||||
| 		const copy = deepClone(activity); | ||||
| 		if (!copy.to) copy.to = ['https://www.w3.org/ns/activitystreams#Public']; | ||||
| 	 | ||||
| 		const signed = await this.apRendererService.attachLdSignature(copy, user); | ||||
|  |  | |||
|  | @ -9,6 +9,7 @@ import { awaitAll } from '@/misc/prelude/await-all.js'; | |||
| import type { User } from '@/models/entities/User.js'; | ||||
| import type { DriveFile } from '@/models/entities/DriveFile.js'; | ||||
| import { appendQuery, query } from '@/misc/prelude/url.js'; | ||||
| import { deepClone } from '@/misc/clone.js'; | ||||
| import { UtilityService } from '../UtilityService.js'; | ||||
| import { UserEntityService } from './UserEntityService.js'; | ||||
| import { DriveFolderEntityService } from './DriveFolderEntityService.js'; | ||||
|  | @ -55,7 +56,7 @@ export class DriveFileEntityService { | |||
| 
 | ||||
| 	public getPublicProperties(file: DriveFile): DriveFile['properties'] { | ||||
| 		if (file.properties.orientation != null) { | ||||
| 			const properties = structuredClone(file.properties); | ||||
| 			const properties = deepClone(file.properties); | ||||
| 			if (file.properties.orientation >= 5) { | ||||
| 				[properties.width, properties.height] = [properties.height, properties.width]; | ||||
| 			} | ||||
|  |  | |||
							
								
								
									
										18
									
								
								packages/backend/src/misc/clone.ts
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								packages/backend/src/misc/clone.ts
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,18 @@ | |||
| // structredCloneが遅いため
 | ||||
| // SEE: http://var.blog.jp/archives/86038606.html
 | ||||
| 
 | ||||
| type Cloneable = string | number | boolean | null | { [key: string]: Cloneable } | Cloneable[]; | ||||
| 
 | ||||
| export function deepClone<T extends Cloneable>(x: T): T { | ||||
| 	if (typeof x === 'object') { | ||||
| 		if (x === null) return x; | ||||
| 		if (Array.isArray(x)) return x.map(deepClone) as T; | ||||
| 		const obj = {} as Record<string, Cloneable>; | ||||
| 		for (const [k, v] of Object.entries(x)) { | ||||
| 			obj[k] = deepClone(v); | ||||
| 		} | ||||
| 		return obj as T; | ||||
| 	} else { | ||||
| 		return x; | ||||
| 	} | ||||
| } | ||||
|  | @ -26,6 +26,7 @@ import { GalleryPostEntityService } from '@/core/entities/GalleryPostEntityServi | |||
| import { ClipEntityService } from '@/core/entities/ClipEntityService.js'; | ||||
| import { ChannelEntityService } from '@/core/entities/ChannelEntityService.js'; | ||||
| import type { ChannelsRepository, ClipsRepository, GalleryPostsRepository, NotesRepository, PagesRepository, UserProfilesRepository, UsersRepository } from '@/models/index.js'; | ||||
| import { deepClone } from '@/misc/clone.js'; | ||||
| import manifest from './manifest.json' assert { type: 'json' }; | ||||
| import { FeedService } from './FeedService.js'; | ||||
| import { UrlPreviewService } from './UrlPreviewService.js'; | ||||
|  | @ -86,7 +87,7 @@ export class ClientServerService { | |||
| 	} | ||||
| 
 | ||||
| 	private async manifestHandler(ctx: Koa.Context) { | ||||
| 		const res = structuredClone(manifest); | ||||
| 		const res = deepClone(manifest); | ||||
| 
 | ||||
| 		const instance = await this.metaService.fetch(true); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue