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

Incorrect sort key in example #1

Open
Nr18 opened this issue Jul 4, 2022 · 3 comments
Open

Incorrect sort key in example #1

Nr18 opened this issue Jul 4, 2022 · 3 comments

Comments

@Nr18
Copy link

Nr18 commented Jul 4, 2022

I haven't tested your solution bus was looking at the implementation and I think there is an error in your template:

See:

":sk": $util.dynamodb.toDynamoDBJson("SITE#$ctx.args.domain")

Shouldn't the SK be POST#? The post is created with POST#${id} as sort key!

@alexdebrie
Copy link
Owner

Hey @Nr18, thanks for reaching out.

There are a few ways we could write this, but this should work. My key condition expression is specifying items whose SK is less than (<) the SITE#${domain} sort key, so it will exclude the Site object whose sort key is exactly that.

Let me know if you think I'm still wrong! Taking a quick glance at it but I think it should be correct :)

@Nr18
Copy link
Author

Nr18 commented Jul 6, 2022

Ah right so because the P comes before the S in the alphabet it is smaller and thus the posts are fetched. Is that assumption correct?

So if that is correct and you would introduce AUTHOR#{id} in the same partition those would also be fetched as a side effect of this query. Therefor I would personally use the begins_with(SK, :sk) and alter the :sk too POST#. This way you guarantee that you are only fetching posts in the getPostsForSite call.

@alexdebrie
Copy link
Owner

Yep, that's exactly right! And it's a good point -- the begins_with() would be a little safer there :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants