Fix setTag logic to prevent high cpu load on rds #572
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For now, whenever we want to set a tag on a resource, it will always fetch all tags from the dbs into memory, and then do a diff to figure out what tags never exist in the db. Loading all tags at once creates a lot of load on the rds if the number of tags is huge when number of setTag request is high.
For this PR, I also remove some unused code.
Instead of fetching all tags into memory, we will instead do
Even though, there is no unit test for tag component, there are lots of existing tests in the functional test, and I also add one more functional test to cover more scenarios.
Since the logic I change should have no impact on the core logic, we should expect the functionalTest to have the same result before and after this change.
Finally, in order to make this insert query fast, we will need to build a composite index on (lookup_id, values_string)