enhance(backend): UserListMembershipにユーザーリストの作成者IDを非正規化
This commit is contained in:
parent
ca022cbbdf
commit
5601ed0914
21
packages/backend/migration/1696807733453-userListUserId.js
Normal file
21
packages/backend/migration/1696807733453-userListUserId.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class UserListUserId1696807733453 {
|
||||||
|
name = 'UserListUserId1696807733453'
|
||||||
|
|
||||||
|
async up(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "user_list_membership" ADD "userListUserId" character varying(32) NOT NULL DEFAULT ''`);
|
||||||
|
const memberships = await queryRunner.query(`SELECT "id", "userListId" FROM "user_list_membership"`);
|
||||||
|
for(let i = 0; i < memberships.length; i++) {
|
||||||
|
const userList = await queryRunner.query(`SELECT "userId" FROM "user_list" WHERE "id" = $1`, [memberships[i].userListId]);
|
||||||
|
await queryRunner.query(`UPDATE "user_list_membership" SET "userListUserId" = $1 WHERE "id" = $2`, [userList[0].userId, memberships[i].id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "user_list_membership" DROP COLUMN "userListUserId"`);
|
||||||
|
}
|
||||||
|
}
|
16
packages/backend/migration/1696808725134-userListUserId-2.js
Normal file
16
packages/backend/migration/1696808725134-userListUserId-2.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: syuilo and other misskey contributors
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
|
||||||
|
export class UserListUserId21696808725134 {
|
||||||
|
name = 'UserListUserId21696808725134'
|
||||||
|
|
||||||
|
async up(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "user_list_membership" ALTER COLUMN "userListUserId" DROP DEFAULT`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async down(queryRunner) {
|
||||||
|
await queryRunner.query(`ALTER TABLE "user_list_membership" ALTER COLUMN "userListUserId" SET DEFAULT ''`);
|
||||||
|
}
|
||||||
|
}
|
@ -228,7 +228,7 @@ export class AccountMoveService {
|
|||||||
},
|
},
|
||||||
}).then(memberships => memberships.map(membership => membership.userListId));
|
}).then(memberships => memberships.map(membership => membership.userListId));
|
||||||
|
|
||||||
const newMemberships: Map<string, { createdAt: Date; userId: string; userListId: string; }> = new Map();
|
const newMemberships: Map<string, { createdAt: Date; userId: string; userListId: string; userListUserId: string; }> = new Map();
|
||||||
|
|
||||||
// 重複しないようにIDを生成
|
// 重複しないようにIDを生成
|
||||||
const genId = (): string => {
|
const genId = (): string => {
|
||||||
@ -244,6 +244,7 @@ export class AccountMoveService {
|
|||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
userId: dst.id,
|
userId: dst.id,
|
||||||
userListId: membership.userListId,
|
userListId: membership.userListId,
|
||||||
|
userListUserId: membership.userListUserId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,6 +97,7 @@ export class UserListService implements OnApplicationShutdown {
|
|||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
userId: target.id,
|
userId: target.id,
|
||||||
userListId: list.id,
|
userListId: list.id,
|
||||||
|
userListUserId: list.userId,
|
||||||
} as MiUserListMembership);
|
} as MiUserListMembership);
|
||||||
|
|
||||||
this.globalEventService.publishInternalEvent('userListMemberAdded', { userListId: list.id, memberId: target.id });
|
this.globalEventService.publishInternalEvent('userListMemberAdded', { userListId: list.id, memberId: target.id });
|
||||||
|
@ -50,4 +50,11 @@ export class MiUserListMembership {
|
|||||||
default: false,
|
default: false,
|
||||||
})
|
})
|
||||||
public withReplies: boolean;
|
public withReplies: boolean;
|
||||||
|
|
||||||
|
//#region Denormalized fields
|
||||||
|
@Column({
|
||||||
|
...id(),
|
||||||
|
})
|
||||||
|
public userListUserId: MiUser['id'];
|
||||||
|
//#endregion
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user