diff --git a/app/db/empty-values-noop-plugin.ts b/app/db/empty-values-noop-plugin.ts new file mode 100644 index 000000000..ade5c6f96 --- /dev/null +++ b/app/db/empty-values-noop-plugin.ts @@ -0,0 +1,58 @@ +import { + type InsertQueryNode, + type KyselyPlugin, + type PluginTransformQueryArgs, + type PluginTransformResultArgs, + type QueryResult, + RawNode, + type RootOperationNode, + SelectionNode, + SelectQueryNode, + type UnknownRow, + ValuesNode, + WhereNode, +} from "kysely"; + +/** + * Makes inserting an empty array of values a no-op instead of a syntax error. + * Kysely compiles `.values([])` into invalid SQL, so without this plugin every + * dynamic multi-row insert would need a length check before it. The empty + * insert is rewritten into `INSERT INTO "T" SELECT * FROM "T" WHERE 0` which + * inserts zero rows and returns zero rows for any `returning` clause. + */ +export class EmptyValuesNoopPlugin implements KyselyPlugin { + transformQuery(args: PluginTransformQueryArgs): RootOperationNode { + if (args.node.kind !== "InsertQueryNode" || !isEmptyInsert(args.node)) { + return args.node; + } + + const { columns: _columns, ...node } = args.node; + + return Object.freeze({ + ...node, + values: selectNothingFrom(args.node), + }); + } + + async transformResult( + args: PluginTransformResultArgs, + ): Promise> { + return args.result; + } +} + +function isEmptyInsert(node: InsertQueryNode) { + return ( + node.values !== undefined && + ValuesNode.is(node.values) && + node.values.values.length === 0 + ); +} + +function selectNothingFrom(node: InsertQueryNode): SelectQueryNode { + return Object.freeze({ + ...SelectQueryNode.createFrom([node.into!]), + selections: Object.freeze([SelectionNode.createSelectAll()]), + where: WhereNode.create(RawNode.createWithSql("0")), + }); +} diff --git a/app/db/sql.ts b/app/db/sql.ts index a1ce304c3..2d205d336 100644 --- a/app/db/sql.ts +++ b/app/db/sql.ts @@ -7,6 +7,7 @@ import { Config } from "~/config"; import { ServerConfig } from "~/config.server"; import { logger } from "~/utils/logger"; import { roundToNDecimalPlaces } from "~/utils/number"; +import { EmptyValuesNoopPlugin } from "./empty-values-noop-plugin"; import { FastParseJSONResultsPlugin } from "./parse-json-results-plugin"; import type { DB } from "./tables"; import { WriteTrackerPlugin } from "./write-tracker"; @@ -46,7 +47,11 @@ export const db = new Kysely({ database: sql, }), log, - plugins: [new FastParseJSONResultsPlugin(), new WriteTrackerPlugin()], + plugins: [ + new EmptyValuesNoopPlugin(), + new FastParseJSONResultsPlugin(), + new WriteTrackerPlugin(), + ], }); // The test database file is created and migrated by scripts/ensure-test-db.ts diff --git a/app/features/art/ArtRepository.server.ts b/app/features/art/ArtRepository.server.ts index fb19c9f77..83b75d470 100644 --- a/app/features/art/ArtRepository.server.ts +++ b/app/features/art/ArtRepository.server.ts @@ -357,12 +357,10 @@ export async function insert(args: InsertArtArgs) { .returningAll() .executeTakeFirstOrThrow(); - if (args.linkedUsers.length > 0) { - await trx - .insertInto("ArtUserMetadata") - .values(args.linkedUsers.map((userId) => ({ artId: art.id, userId }))) - .execute(); - } + await trx + .insertInto("ArtUserMetadata") + .values(args.linkedUsers.map((userId) => ({ artId: art.id, userId }))) + .execute(); await insertTags({ tags: args.tags, authorId, artId: art.id }, trx); @@ -402,12 +400,10 @@ export async function update(id: number, args: UpdateArtArgs) { await trx.deleteFrom("ArtUserMetadata").where("artId", "=", id).execute(); - if (args.linkedUsers.length > 0) { - await trx - .insertInto("ArtUserMetadata") - .values(args.linkedUsers.map((userId) => ({ artId: id, userId }))) - .execute(); - } + await trx + .insertInto("ArtUserMetadata") + .values(args.linkedUsers.map((userId) => ({ artId: id, userId }))) + .execute(); await trx.deleteFrom("TaggedArt").where("artId", "=", id).execute(); @@ -429,8 +425,6 @@ async function insertTags( }, trx: Transaction, ) { - if (tags.length === 0) return; - const newTagNames = tags .filter((tag) => !tag.id) .map((tag) => { @@ -440,16 +434,13 @@ async function insertTags( return tag.name; }); - const newTagIds = - newTagNames.length > 0 - ? ( - await trx - .insertInto("ArtTag") - .values(newTagNames.map((name) => ({ name, authorId }))) - .returning("ArtTag.id") - .execute() - ).map((tag) => tag.id) - : []; + const newTagIds = ( + await trx + .insertInto("ArtTag") + .values(newTagNames.map((name) => ({ name, authorId }))) + .returning("ArtTag.id") + .execute() + ).map((tag) => tag.id); const tagIds = [ ...tags.flatMap((tag) => (tag.id ? [tag.id] : [])), diff --git a/app/features/badges/BadgeRepository.server.test.ts b/app/features/badges/BadgeRepository.server.test.ts index 591597641..2c7bcc652 100644 --- a/app/features/badges/BadgeRepository.server.test.ts +++ b/app/features/badges/BadgeRepository.server.test.ts @@ -48,6 +48,33 @@ describe("syncXPBadges", () => { }); }); +describe("replaceManagers", () => { + test("empty list clears existing managers", async () => { + const user = await UserFactory.create(); + const badge = await BadgeFactory.create(null, { managerIds: [user.id] }); + + await BadgeRepository.replaceManagers({ + badgeId: badge.id, + managerIds: [], + }); + + const updated = await BadgeRepository.findById(badge.id); + expect(updated?.managers).toHaveLength(0); + }); +}); + +describe("replaceOwners", () => { + test("empty list clears existing owners", async () => { + const user = await UserFactory.create(); + const badge = await BadgeFactory.create(null, { ownerIds: [user.id] }); + + await BadgeRepository.replaceOwners({ badgeId: badge.id, ownerIds: [] }); + + const updated = await BadgeRepository.findById(badge.id); + expect(updated?.owners).toHaveLength(0); + }); +}); + /** Gives the user a linked X Rank player whose one placement is worth `power`. */ const givePeakXp = (userId: number, power: number) => XRankPlacementFactory.create( diff --git a/app/features/badges/BadgeRepository.server.ts b/app/features/badges/BadgeRepository.server.ts index 7d49eb6b9..24771147f 100644 --- a/app/features/badges/BadgeRepository.server.ts +++ b/app/features/badges/BadgeRepository.server.ts @@ -180,17 +180,15 @@ export function replaceManagers({ .where("badgeId", "=", badgeId) .execute(); - if (managerIds.length > 0) { - await trx - .insertInto("BadgeManager") - .values( - managerIds.map((userId) => ({ - badgeId, - userId, - })), - ) - .execute(); - } + await trx + .insertInto("BadgeManager") + .values( + managerIds.map((userId) => ({ + badgeId, + userId, + })), + ) + .execute(); }); } @@ -207,23 +205,21 @@ export function replaceOwners({ .where("badgeId", "=", badgeId) .execute(); - if (ownerIds.length > 0) { - const counts = new Map(); - for (const userId of ownerIds) { - counts.set(userId, (counts.get(userId) ?? 0) + 1); - } - - await trx - .insertInto("TournamentBadgeOwner") - .values( - Array.from(counts, ([userId, count]) => ({ - badgeId, - userId, - count, - })), - ) - .execute(); + const counts = new Map(); + for (const userId of ownerIds) { + counts.set(userId, (counts.get(userId) ?? 0) + 1); } + + await trx + .insertInto("TournamentBadgeOwner") + .values( + Array.from(counts, ([userId, count]) => ({ + badgeId, + userId, + count, + })), + ) + .execute(); }); } @@ -262,8 +258,6 @@ export async function syncXPBadges() { return badgeId ? [{ badgeId, userId }] : []; }); - if (badgeOwners.length === 0) return; - await trx.insertInto("TournamentBadgeOwner").values(badgeOwners).execute(); }); } diff --git a/app/features/builds/BuildRepository.server.ts b/app/features/builds/BuildRepository.server.ts index fbb10585a..9e5995d34 100644 --- a/app/features/builds/BuildRepository.server.ts +++ b/app/features/builds/BuildRepository.server.ts @@ -546,10 +546,8 @@ async function insertBuildChildren( abilityPoints, })), ); - if (weaponAbilityRows.length > 0) { - await trx - .insertInto("BuildWeaponAbility") - .values(weaponAbilityRows) - .execute(); - } + await trx + .insertInto("BuildWeaponAbility") + .values(weaponAbilityRows) + .execute(); } diff --git a/app/features/calendar/CalendarRepository.server.ts b/app/features/calendar/CalendarRepository.server.ts index eb0be7211..f31000ea4 100644 --- a/app/features/calendar/CalendarRepository.server.ts +++ b/app/features/calendar/CalendarRepository.server.ts @@ -506,19 +506,17 @@ export async function insert(args: CreateArgs) { .executeTakeFirstOrThrow() ).id; - if (copiedStaff.length > 0) { - await trx - .insertInto("TournamentStaff") - .columns(["role", "userId", "tournamentId"]) - .values( - copiedStaff.map((staff) => ({ - role: staff.role, - userId: staff.userId, - tournamentId: tournamentId!, - })), - ) - .execute(); - } + await trx + .insertInto("TournamentStaff") + .columns(["role", "userId", "tournamentId"]) + .values( + copiedStaff.map((staff) => ({ + role: staff.role, + userId: staff.userId, + tournamentId: tournamentId!, + })), + ) + .execute(); } const avatarImgId = args.avatarFileName @@ -750,8 +748,6 @@ function insertBadges( { eventId, badges }: { eventId: number; badges: CreateArgs["badges"] }, trx: Transaction, ) { - if (!badges.length) return; - return trx .insertInto("CalendarEventBadge") .values( @@ -788,8 +784,6 @@ export function upsertReportedScores(args: { .where("eventId", "=", args.eventId) .execute(); - if (args.results.length === 0) return; - const insertedTeams = await trx .insertInto("CalendarEventResultTeam") .values( @@ -812,8 +806,6 @@ export function upsertReportedScores(args: { })), ); - if (players.length === 0) return; - await trx.insertInto("CalendarEventResultPlayer").values(players).execute(); }); } @@ -840,8 +832,6 @@ async function upsertMapPool( ) .execute(); - if (!mapPoolMaps.length) return; - await trx .insertInto("MapPoolMap") .values( diff --git a/app/features/live-streams/LiveStreamRepository.server.ts b/app/features/live-streams/LiveStreamRepository.server.ts index 188f6729d..819c3f21d 100644 --- a/app/features/live-streams/LiveStreamRepository.server.ts +++ b/app/features/live-streams/LiveStreamRepository.server.ts @@ -7,9 +7,7 @@ export function replaceAll(streams: Omit[]) { return db.transaction().execute(async (trx) => { await trx.deleteFrom("LiveStream").execute(); - if (streams.length > 0) { - await trx.insertInto("LiveStream").values(streams).execute(); - } + await trx.insertInto("LiveStream").values(streams).execute(); }); } @@ -21,8 +19,6 @@ export function replaceAll(streams: Omit[]) { export function insertTournamentStreamers( rows: Omit[], ) { - if (rows.length === 0) return Promise.resolve([]); - return db .insertInto("TournamentStreamer") .values(rows) diff --git a/app/features/match-profile/MatchProfileRepository.server.ts b/app/features/match-profile/MatchProfileRepository.server.ts index ed6549269..965038917 100644 --- a/app/features/match-profile/MatchProfileRepository.server.ts +++ b/app/features/match-profile/MatchProfileRepository.server.ts @@ -65,19 +65,17 @@ export async function updateOwnMatchProfile({ .where("userId", "=", userId) .execute(); - if (weaponPool.length > 0) { - await trx - .insertInto("UserWeaponPool") - .values( - weaponPool.map((wpn, i) => ({ - userId, - sortOrder: i, - weaponSplId: wpn.id, - isFavorite: toDBBoolean(wpn.isFavorite), - })), - ) - .execute(); - } + await trx + .insertInto("UserWeaponPool") + .values( + weaponPool.map((wpn, i) => ({ + userId, + sortOrder: i, + weaponSplId: wpn.id, + isFavorite: toDBBoolean(wpn.isFavorite), + })), + ) + .execute(); await trx .updateTable("User") diff --git a/app/features/sendouq-match/MatchSkillRepository.server.ts b/app/features/sendouq-match/MatchSkillRepository.server.ts index 712fb2f07..6e633ad7d 100644 --- a/app/features/sendouq-match/MatchSkillRepository.server.ts +++ b/app/features/sendouq-match/MatchSkillRepository.server.ts @@ -59,13 +59,11 @@ async function insertMatchSkillsInTransaction( } } - if (teamUsers.length > 0) { - await executor - .insertInto("SkillTeamUser") - .values(teamUsers) - .onConflict((oc) => oc.columns(["skillId", "userId"]).doNothing()) - .execute(); - } + await executor + .insertInto("SkillTeamUser") + .values(teamUsers) + .onConflict((oc) => oc.columns(["skillId", "userId"]).doNothing()) + .execute(); if (!oldMatchMemento) return; diff --git a/app/features/sendouq-match/PlayerStatRepository.server.ts b/app/features/sendouq-match/PlayerStatRepository.server.ts index e6b7009b9..f96e96842 100644 --- a/app/features/sendouq-match/PlayerStatRepository.server.ts +++ b/app/features/sendouq-match/PlayerStatRepository.server.ts @@ -26,8 +26,6 @@ export function upsertMapResults( >[], trx?: Transaction, ) { - if (results.length === 0) return; - const executor = trx ?? db; return executor @@ -418,8 +416,6 @@ export function upsertPlayerResults( results: Tables["PlayerResult"][], trx?: Transaction, ) { - if (results.length === 0) return; - const executor = trx ?? db; return executor diff --git a/app/features/sendouq-match/ReportedWeaponRepository.server.ts b/app/features/sendouq-match/ReportedWeaponRepository.server.ts index 6bb388a1d..b739af0ca 100644 --- a/app/features/sendouq-match/ReportedWeaponRepository.server.ts +++ b/app/features/sendouq-match/ReportedWeaponRepository.server.ts @@ -45,9 +45,7 @@ export async function replaceByMatchId( .where("groupMatchId", "=", matchId) .execute(); - if (weapons.length > 0) { - await executor.insertInto("ReportedWeapon").values(weapons).execute(); - } + await executor.insertInto("ReportedWeapon").values(weapons).execute(); } export async function deleteOwnByMapIndex({ diff --git a/app/features/sendouq/SQGroupRepository.server.ts b/app/features/sendouq/SQGroupRepository.server.ts index ea16d9dc1..91d1d56a7 100644 --- a/app/features/sendouq/SQGroupRepository.server.ts +++ b/app/features/sendouq/SQGroupRepository.server.ts @@ -566,21 +566,19 @@ export async function closeExpiredContinueVotes() { ) .execute(); - if (members.length > 0) { - await trx - .insertInto("GroupMatchContinueVote") - .values( - members.map((member) => ({ - groupId: member.groupId, - userId: member.userId, - isContinuing: 0 as const, - })), - ) - .onConflict((oc) => - oc.columns(["groupId", "userId"]).doUpdateSet({ isContinuing: 0 }), - ) - .execute(); - } + await trx + .insertInto("GroupMatchContinueVote") + .values( + members.map((member) => ({ + groupId: member.groupId, + userId: member.userId, + isContinuing: 0 as const, + })), + ) + .onConflict((oc) => + oc.columns(["groupId", "userId"]).doUpdateSet({ isContinuing: 0 }), + ) + .execute(); } return { diff --git a/app/features/splatoon-rotations/SplatoonRotationRepository.server.ts b/app/features/splatoon-rotations/SplatoonRotationRepository.server.ts index f4a2ebf28..152df2f4a 100644 --- a/app/features/splatoon-rotations/SplatoonRotationRepository.server.ts +++ b/app/features/splatoon-rotations/SplatoonRotationRepository.server.ts @@ -10,9 +10,7 @@ export async function replaceAll( await db.transaction().execute(async (trx) => { await trx.deleteFrom("SplatoonRotation").execute(); - if (rotations.length > 0) { - await trx.insertInto("SplatoonRotation").values(rotations).execute(); - } + await trx.insertInto("SplatoonRotation").values(rotations).execute(); }); cachedRotations = await queryAll(); diff --git a/app/features/tournament-bracket/TournamentMatchVodRepository.server.ts b/app/features/tournament-bracket/TournamentMatchVodRepository.server.ts index 6f1cad25b..eefb2def9 100644 --- a/app/features/tournament-bracket/TournamentMatchVodRepository.server.ts +++ b/app/features/tournament-bracket/TournamentMatchVodRepository.server.ts @@ -36,8 +36,6 @@ export function findVodsByTournamentId(tournamentId: number) { } export function insertMany(vods: Omit[]) { - if (vods.length === 0) return; - return db .insertInto("TournamentMatchVod") .values(vods) diff --git a/app/features/tournament-organization/TournamentOrganizationRepository.server.ts b/app/features/tournament-organization/TournamentOrganizationRepository.server.ts index 38ef6979b..e7ebd36aa 100644 --- a/app/features/tournament-organization/TournamentOrganizationRepository.server.ts +++ b/app/features/tournament-organization/TournamentOrganizationRepository.server.ts @@ -636,17 +636,15 @@ export function update({ .where("TournamentOrganizationBadge.organizationId", "=", id) .execute(); - if (badges.length > 0) { - await trx - .insertInto("TournamentOrganizationBadge") - .values( - badges.map((badgeId) => ({ - organizationId: id, - badgeId, - })), - ) - .execute(); - } + await trx + .insertInto("TournamentOrganizationBadge") + .values( + badges.map((badgeId) => ({ + organizationId: id, + badgeId, + })), + ) + .execute(); return updatedOrg; }); diff --git a/app/features/tournament/TournamentRepository.server.ts b/app/features/tournament/TournamentRepository.server.ts index 8dc787058..1774e32b9 100644 --- a/app/features/tournament/TournamentRepository.server.ts +++ b/app/features/tournament/TournamentRepository.server.ts @@ -837,18 +837,16 @@ export function setStaff({ .where("tournamentId", "=", tournamentId) .execute(); - if (staff.length > 0) { - await trx - .insertInto("TournamentStaff") - .values( - staff.map((staffer) => ({ - tournamentId, - userId: staffer.userId, - role: staffer.role, - })), - ) - .execute(); - } + await trx + .insertInto("TournamentStaff") + .values( + staff.map((staffer) => ({ + tournamentId, + userId: staffer.userId, + role: staffer.role, + })), + ) + .execute(); }); } @@ -1142,29 +1140,25 @@ export function finalize({ } } - if (skillTeamUsers.length > 0) { - await trx - .insertInto("SkillTeamUser") - .values(skillTeamUsers) - .onConflict((oc) => oc.columns(["skillId", "userId"]).doNothing()) - .execute(); - } + await trx + .insertInto("SkillTeamUser") + .values(skillTeamUsers) + .onConflict((oc) => oc.columns(["skillId", "userId"]).doNothing()) + .execute(); // SeedingSkill has `on conflict replace` set in its migration - if (summary.seedingSkills.length > 0) { - await trx - .insertInto("SeedingSkill") - .values( - summary.seedingSkills.map((seedingSkill) => ({ - type: seedingSkill.type, - mu: seedingSkill.mu, - sigma: seedingSkill.sigma, - ordinal: seedingSkill.ordinal, - userId: seedingSkill.userId, - })), - ) - .execute(); - } + await trx + .insertInto("SeedingSkill") + .values( + summary.seedingSkills.map((seedingSkill) => ({ + type: seedingSkill.type, + mu: seedingSkill.mu, + sigma: seedingSkill.sigma, + ordinal: seedingSkill.ordinal, + userId: seedingSkill.userId, + })), + ) + .execute(); if (summary.mapResultDeltas.length > 0) { invariant(seasonValue !== null, "Season missing for map result"); @@ -1243,12 +1237,7 @@ export function finalize({ userId, })), ); - if (badgeOwners.length > 0) { - await trx - .insertInto("TournamentBadgeOwner") - .values(badgeOwners) - .execute(); - } + await trx.insertInto("TournamentBadgeOwner").values(badgeOwners).execute(); if (trophyReceiver && trophyReceiver.userIds.length > 0) { const tournamentRow = await trx @@ -1290,12 +1279,10 @@ export function finalize({ div: tournamentResult.div, })); - if (tournamentResults.length > 0) { - await trx - .insertInto("TournamentResult") - .values(tournamentResults) - .execute(); - } + await trx + .insertInto("TournamentResult") + .values(tournamentResults) + .execute(); await trx .updateTable("Tournament") diff --git a/app/features/tournament/TournamentTeamRepository.server.ts b/app/features/tournament/TournamentTeamRepository.server.ts index b1bec87fd..b407d9da3 100644 --- a/app/features/tournament/TournamentTeamRepository.server.ts +++ b/app/features/tournament/TournamentTeamRepository.server.ts @@ -531,17 +531,15 @@ export function copyFromAnotherTournament({ ) .execute(); - if (oldMapPool.length > 0) { - await trx - .insertInto("MapPoolMap") - .values( - oldMapPool.map((mapPoolMap) => ({ - ...mapPoolMap, - tournamentTeamId: newTeam.id, - })), - ) - .execute(); - } + await trx + .insertInto("MapPoolMap") + .values( + oldMapPool.map((mapPoolMap) => ({ + ...mapPoolMap, + tournamentTeamId: newTeam.id, + })), + ) + .execute(); }); } @@ -893,18 +891,16 @@ export function upsertCounterpickMaps({ .where("MapPoolMap.tournamentTeamId", "=", tournamentTeamId) .execute(); - if (mapPool.stageModePairs.length > 0) { - await trx - .insertInto("MapPoolMap") - .values( - mapPool.stageModePairs.map(({ stageId, mode }) => ({ - tournamentTeamId, - stageId, - mode, - })), - ) - .execute(); - } + await trx + .insertInto("MapPoolMap") + .values( + mapPool.stageModePairs.map(({ stageId, mode }) => ({ + tournamentTeamId, + stageId, + mode, + })), + ) + .execute(); }); } diff --git a/app/features/trophies/TrophyRepository.server.ts b/app/features/trophies/TrophyRepository.server.ts index b0ef622e2..74a3be8d5 100644 --- a/app/features/trophies/TrophyRepository.server.ts +++ b/app/features/trophies/TrophyRepository.server.ts @@ -605,8 +605,6 @@ async function replaceSpecialTrophyOwners({ } await deleteStale.execute(); - if (userIds.length === 0) return; - await trx .insertInto("SpecialTrophyOwner") .values( diff --git a/app/features/user-page/UserRepository.server.ts b/app/features/user-page/UserRepository.server.ts index eed013d3b..460730980 100644 --- a/app/features/user-page/UserRepository.server.ts +++ b/app/features/user-page/UserRepository.server.ts @@ -294,8 +294,6 @@ export async function upsertWidgets( return db.transaction().execute(async (trx) => { await trx.deleteFrom("UserWidget").where("userId", "=", userId).execute(); - if (widgets.length === 0) return; - await trx .insertInto("UserWidget") .values( @@ -1106,19 +1104,17 @@ export function updateOwnProfile(args: UpdateProfileArgs) { .execute(); } - if (args.weapons.length > 0) { - await trx - .insertInto("UserWeapon") - .values( - args.weapons.map((weapon, i) => ({ - userId, - weaponSplId: weapon.weaponSplId, - isFavorite: weapon.isFavorite ?? 0, - order: i + 1, - })), - ) - .execute(); - } + await trx + .insertInto("UserWeapon") + .values( + args.weapons.map((weapon, i) => ({ + userId, + weaponSplId: weapon.weaponSplId, + isFavorite: weapon.isFavorite ?? 0, + order: i + 1, + })), + ) + .execute(); return trx .updateTable("User") @@ -1220,17 +1216,15 @@ export function updateOwnResultHighlights(args: UpdateResultHighlightsArgs) { .where("userId", "=", userId) .execute(); - if (args.resultTeamIds.length > 0) { - await trx - .insertInto("UserResultHighlight") - .values( - args.resultTeamIds.map((teamId) => ({ - userId, - teamId, - })), - ) - .execute(); - } + await trx + .insertInto("UserResultHighlight") + .values( + args.resultTeamIds.map((teamId) => ({ + userId, + teamId, + })), + ) + .execute(); await trx .updateTable("TournamentResult") diff --git a/app/features/vods/VodRepository.server.ts b/app/features/vods/VodRepository.server.ts index 6832e7f6c..060ba68eb 100644 --- a/app/features/vods/VodRepository.server.ts +++ b/app/features/vods/VodRepository.server.ts @@ -287,7 +287,6 @@ export async function insert( .executeTakeFirstOrThrow(); videoId = result.id; } - if (args.matches.length === 0) return { ...video, id: videoId }; const insertedMatches = await trx .insertInto("VideoMatch") @@ -318,9 +317,7 @@ export async function insert( })), ); - if (players.length > 0) { - await trx.insertInto("VideoMatchPlayer").values(players).execute(); - } + await trx.insertInto("VideoMatchPlayer").values(players).execute(); return { ...video, id: videoId }; });