mirror of
https://github.com/whyour/qinglong.git
synced 2026-04-29 00:45:11 +08:00
Address code review: use transactions for label updates, fix variable naming
Agent-Logs-Url: https://github.com/whyour/qinglong/sessions/1436272f-a03a-45af-b57d-869a48ab537d Co-authored-by: whyour <22700758+whyour@users.noreply.github.com>
This commit is contained in:
parent
d4930faedd
commit
ce1a68871a
|
|
@ -201,25 +201,29 @@ export default class EnvService {
|
||||||
|
|
||||||
public async addLabels(ids: number[], labels: string[]) {
|
public async addLabels(ids: number[], labels: string[]) {
|
||||||
const docs = await EnvModel.findAll({ where: { id: ids } });
|
const docs = await EnvModel.findAll({ where: { id: ids } });
|
||||||
for (const doc of docs) {
|
await sequelize.transaction(async (t) => {
|
||||||
const env = doc.get({ plain: true });
|
for (const doc of docs) {
|
||||||
await EnvModel.update(
|
const env = doc.get({ plain: true });
|
||||||
{ labels: Array.from(new Set((env.labels || []).concat(labels))) },
|
await EnvModel.update(
|
||||||
{ where: { id: env.id } },
|
{ labels: Array.from(new Set((env.labels || []).concat(labels))) },
|
||||||
);
|
{ where: { id: env.id }, transaction: t },
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
return await EnvModel.findAll({ where: { id: ids } });
|
return await EnvModel.findAll({ where: { id: ids } });
|
||||||
}
|
}
|
||||||
|
|
||||||
public async removeLabels(ids: number[], labels: string[]) {
|
public async removeLabels(ids: number[], labels: string[]) {
|
||||||
const docs = await EnvModel.findAll({ where: { id: ids } });
|
const docs = await EnvModel.findAll({ where: { id: ids } });
|
||||||
for (const doc of docs) {
|
await sequelize.transaction(async (t) => {
|
||||||
const env = doc.get({ plain: true });
|
for (const doc of docs) {
|
||||||
await EnvModel.update(
|
const env = doc.get({ plain: true });
|
||||||
{ labels: (env.labels || []).filter((label: string) => !labels.includes(label)) },
|
await EnvModel.update(
|
||||||
{ where: { id: env.id } },
|
{ labels: (env.labels || []).filter((label: string) => !labels.includes(label)) },
|
||||||
);
|
{ where: { id: env.id }, transaction: t },
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
return await EnvModel.findAll({ where: { id: ids } });
|
return await EnvModel.findAll({ where: { id: ids } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
2
src/pages/env/index.tsx
vendored
2
src/pages/env/index.tsx
vendored
|
|
@ -128,7 +128,7 @@ const Env = () => {
|
||||||
render: (labels: string[], record: any) => {
|
render: (labels: string[], record: any) => {
|
||||||
return (
|
return (
|
||||||
<Space size={[0, 4]} wrap>
|
<Space size={[0, 4]} wrap>
|
||||||
{labels?.filter((l) => l).map((label) => (
|
{labels?.filter((label) => label).map((label) => (
|
||||||
<Tag key={label} color="blue">
|
<Tag key={label} color="blue">
|
||||||
{label}
|
{label}
|
||||||
</Tag>
|
</Tag>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user