From 652bd4ab2333e10e64b04b382da316624fe36bdb Mon Sep 17 00:00:00 2001 From: James Date: Wed, 9 Feb 2022 13:26:20 -0500 Subject: [PATCH] chore: cleans up duplicative versions --- src/versions/saveCollectionVersion.ts | 7 +++++++ src/versions/saveGlobalVersion.ts | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/versions/saveCollectionVersion.ts b/src/versions/saveCollectionVersion.ts index 05ae81db45..85f0cd7983 100644 --- a/src/versions/saveCollectionVersion.ts +++ b/src/versions/saveCollectionVersion.ts @@ -42,6 +42,13 @@ export const saveCollectionVersion = async ({ }); if (latestVersion) { + // If the latest version is a draft, no need to re-save it + // Example: when "promoting" a draft to published, the draft already exists. + // Instead, return null + if (latestVersion?.version?._status === 'draft') { + return null; + } + version = latestVersion.version; version = JSON.parse(JSON.stringify(version)); version = sanitizeInternalFields(version); diff --git a/src/versions/saveGlobalVersion.ts b/src/versions/saveGlobalVersion.ts index e0598b8d04..b7c2e48851 100644 --- a/src/versions/saveGlobalVersion.ts +++ b/src/versions/saveGlobalVersion.ts @@ -37,6 +37,13 @@ export const saveGlobalVersion = async ({ }); if (latestVersion) { + // If the latest version is a draft, no need to re-save it + // Example: when "promoting" a draft to published, the draft already exists. + // Instead, return null + if (latestVersion?.version?._status === 'draft') { + return null; + } + version = latestVersion.version; version = JSON.parse(JSON.stringify(version)); version = sanitizeInternalFields(version);