mirror of
https://github.com/misskey-dev/misskey.git
synced 2026-05-22 10:34:13 +02:00
refactor: DriveFileEntityServiceとDriveFolderEntityServiceの複数件取得をリファクタ (#17064)
* refactor: DriveFileEntityServiceとDriveFolderEntityServiceの複数件取得をリファクタ
* add test
* fix
* Update packages/backend/src/core/entities/DriveFolderEntityService.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update packages/backend/test/unit/entities/DriveFolderEntityService.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Update packages/backend/src/core/entities/DriveFileEntityService.ts
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
* Revert "Update packages/backend/src/core/entities/DriveFileEntityService.ts"
This reverts commit 83bb9564cf.
---------
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
27
packages/backend/src/misc/split-id-and-objects.ts
Normal file
27
packages/backend/src/misc/split-id-and-objects.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* idとオブジェクトを分離する
|
||||
* @param input idまたはオブジェクトの配列
|
||||
* @returns idの配列とオブジェクトの配列
|
||||
*/
|
||||
export function splitIdAndObjects<T extends { id: string }>(input: (T | string)[]): { ids: string[]; objects: T[] } {
|
||||
const ids: string[] = [];
|
||||
const objects : T[] = [];
|
||||
|
||||
for (const item of input) {
|
||||
if (typeof item === 'string') {
|
||||
ids.push(item);
|
||||
} else {
|
||||
objects.push(item);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
ids,
|
||||
objects,
|
||||
};
|
||||
}
|
||||
21
packages/backend/src/misc/unique-by-key.ts
Normal file
21
packages/backend/src/misc/unique-by-key.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: syuilo and misskey-project
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
/**
|
||||
* itemsの中でkey関数が返す値が重複しないようにした配列を返す
|
||||
* @param items 重複を除去したい配列
|
||||
* @param key 重複判定に使うキーを返す関数
|
||||
* @returns 重複を除去した配列
|
||||
*/
|
||||
export function uniqueByKey<TItem, TKey = string>(items: Iterable<TItem>, key: (item: TItem) => TKey): TItem[] {
|
||||
const map = new Map<TKey, TItem>();
|
||||
for (const item of items) {
|
||||
const k = key(item);
|
||||
if (!map.has(k)) {
|
||||
map.set(k, item);
|
||||
}
|
||||
}
|
||||
return [...map.values()];
|
||||
}
|
||||
Reference in New Issue
Block a user