Dynamodb GSI Use Case Skilltransfers app
Updated: Nov 19
Goal: Show the number of peers per course for the user
For our app to minimize the number of calls to the backend and optimize the speed of the app, we will add the count of peers to course data. So every time the data of the course is being called it will also have that information directly available.
1. Adding a filter when a skill is assigned to a user
While a skill is assigned to a user we also create a filter and tenant filter which we later use for gsi in our DynamoDB.
2. Getting peers from the course without duplicates
This gsi requires tenant id and course id which can give us all the peers of that course for a particular tenant. Furthermore to make sure peer in a course doesn't get counted more than once I added a function which takes data and removes redundant peer objects if there are any.
3. Adding the count to the course data
We get peer count by calculating the number of unique objects in peer count data which is an array of objects. This peer count data also contains department id so we fetch course data with the help of tenant id department id and course id.
Calculated peer count is then merged to course data and we update the course data by new data that is new field peerCount added in course data.