Skip to content

Commit

Permalink
Load one file for the list of paths (#2118)
Browse files Browse the repository at this point in the history
  • Loading branch information
fiskus authored Mar 23, 2021
1 parent 3c84a98 commit dd5ab21
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
42 changes: 33 additions & 9 deletions catalog/app/containers/Bucket/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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`)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion catalog/app/utils/BucketPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit dd5ab21

Please sign in to comment.