lttkgp / R2-D2

Facebook connector for C-3PO
MIT License
7 stars 4 forks source link

Fix the GSI for DynamoDB to scan latest first #9

Closed ghostwriternr closed 3 years ago

ghostwriternr commented 3 years ago

The keys for the feed table on DynamoDB are: Partition Key: facebook_id Sort Key: created_time

And for the GSI are: Partition Key: facebook_id Sort Key: is_parsed

This lets the GSI be a sparse index as R2-D2 deletes is_parsed (initially false after a post is parsed). But, DynamoDB scan returns the responses in ascending order of facebook_id, which is haphazard and not in a latest-first fashion, which would be better.

A GSI like below might help: Partition Key: is_parsed Sort Key: created_time

And fetch the latest posts using a query rather than a scan since the query API allows for a ScanIndexForward flag to scan in reverse order.

Possible issues: