Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: chunked backup creation #496

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/db/fauna/resources/Function/createUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,36 @@ const body = Query(
},
If(
IsNonEmpty(Var('uploadMatch')),
Get(Var('uploadMatch')),
Do(
Foreach(
Select('backupUrls', Var('data')),
Lambda(
['url'],
Let(
{
upload: Select('ref', Get(Var('uploadMatch'))),
backupMatch: Match(
Index('backup_by_upload_and_url'),
Var('upload'),
Var('url')
)
},
If(
IsNonEmpty(Var('backupMatch')),
Get(Var('backupMatch')),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to verify my understanding here, the true_expr in this If ... Get(Var('backupMatch')),is basically unused right? it's just there because Fauna doesn't support a simple If...then only an If...then...else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes sir! I "return" the Backup because the Create below also returns the Backup, either way nothing uses the returned value

Create('Backup', {
data: {
upload: Var('upload'),
url: Var('url'),
created: Now()
}
})
)
)
)
),
Get(Var('uploadMatch'))
),
Let(
{
upload: Create('Upload', {
Expand Down
35 changes: 35 additions & 0 deletions packages/db/fauna/resources/Index/backupByUploadAndUrl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import fauna from 'faunadb'

const {
CreateIndex,
Collection,
If,
Index,
Exists,
Not
} = fauna

/**
* Usage:
*
* Match(
* Index('backup_by_upload_and_url'),
* Ref(Collection('Upload'), Var('uploadId')),
* Var('url')
* )
*/
const index = {
name: 'backup_by_upload_and_url',
source: Collection('Backup'),
terms: [
{ field: ['data', 'upload'] },
{ field: ['data', 'url'] }
]
}

// indexes cannot be updated
export default If(
Not(Exists(Index(index.name))),
CreateIndex(index),
Index(index.name)
)