From dd5ab21be40bc2d283995d512ae27cc016df78f8 Mon Sep 17 00:00:00 2001 From: Maxim Chervonny Date: Tue, 23 Mar 2021 09:06:45 +0300 Subject: [PATCH] Load one file for the list of paths (#2118) --- catalog/app/containers/Bucket/requests.js | 42 ++++++++++++++++++----- catalog/app/utils/BucketPreferences.tsx | 5 ++- 2 files changed, 37 insertions(+), 10 deletions(-) diff --git a/catalog/app/containers/Bucket/requests.js b/catalog/app/containers/Bucket/requests.js index c9cb4d007af..5295d19efc9 100644 --- a/catalog/app/containers/Bucket/requests.js +++ b/catalog/app/containers/Bucket/requests.js @@ -218,11 +218,29 @@ export const bucketStats = async ({ req, s3, bucket, overviewUrl }) => { throw new Error('Stats unavailable') } +const ensureObjectIsPresentInCollection = async ({ s3, bucket, keys, version }) => { + if (!keys.length) return null + + const [key, ...keysTail] = keys + const fileExists = await ensureObjectIsPresent({ + s3, + bucket, + key, + version, + }) + + return ( + fileExists || + (await ensureObjectIsPresentInCollection({ s3, bucket, keys: keysTail })) + ) +} + const fetchFileVersioned = async ({ s3, bucket, path, version }) => { - const versionExists = await ensureObjectIsPresent({ + const keys = Array.isArray(path) ? path : [path] + const versionExists = await ensureObjectIsPresentInCollection({ s3, bucket, - key: path, + keys, version, }) if (!versionExists) { @@ -234,17 +252,18 @@ const fetchFileVersioned = async ({ s3, bucket, path, version }) => { return s3 .getObject({ Bucket: bucket, - Key: path, + Key: versionExists.key, VersionId: version, }) .promise() } const fetchFileLatest = async ({ s3, bucket, path }) => { - const fileExists = await ensureObjectIsPresent({ + const keys = Array.isArray(path) ? path : [path] + const fileExists = await ensureObjectIsPresentInCollection({ s3, bucket, - key: path, + keys, }) if (!fileExists) { throw new errors.FileNotFound(`${path} for ${bucket} does not exist`) @@ -253,12 +272,12 @@ const fetchFileLatest = async ({ s3, bucket, path }) => { const versions = await objectVersions({ s3, bucket, - path, + path: fileExists.key, }) - const { id } = R.find(R.prop('isLatest'), versions) - const version = id === 'null' ? undefined : id + const latest = R.find(R.prop('isLatest'), versions) + const version = latest && latest.id !== 'null' ? latest.id : undefined - return fetchFileVersioned({ s3, bucket, path, version }) + return fetchFileVersioned({ s3, bucket, path: fileExists.key, version }) } export const fetchFile = R.ifElse(R.prop('version'), fetchFileVersioned, fetchFileLatest) @@ -284,6 +303,11 @@ export const metadataSchema = async ({ s3, schemaUrl }) => { } const WORKFLOWS_CONFIG_PATH = '.quilt/workflows/config.yml' +// TODO: enable this when backend is ready +// const WORKFLOWS_CONFIG_PATH = [ +// '.quilt/workflows/config.yaml', +// '.quilt/workflows/config.yml', +// ] export const workflowsConfig = async ({ s3, bucket }) => { try { diff --git a/catalog/app/utils/BucketPreferences.tsx b/catalog/app/utils/BucketPreferences.tsx index 30c4d578f53..6429c71e89d 100644 --- a/catalog/app/utils/BucketPreferences.tsx +++ b/catalog/app/utils/BucketPreferences.tsx @@ -65,7 +65,10 @@ function parse(bucketPreferencesYaml: string): BucketPreferences { } } -const BUCKET_PREFERENCES_PATH = '.quilt/catalog/config.yml' +const BUCKET_PREFERENCES_PATH = [ + '.quilt/catalog/config.yaml', + '.quilt/catalog/config.yml', +] const fetchBucketPreferences = async ({ s3, bucket }: { s3: any; bucket: string }) => { try {