Add rate limiting to Reddit integration#1015
Merged
garrrikkotua merged 5 commits intomainfrom Jun 30, 2023
Merged
Conversation
themarolt
requested changes
Jun 22, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Changes proposed ✍️
What
🤖 Generated by Copilot at 5ba51d7
This pull request adds rate limiting functionality to the Reddit API integration using a Redis cache and a rate limiter class. It modifies the
services/libs/integrationsandservices/apps/integration_stream_workerpackages to use the@crowd/redispackage as a dependency and pass the global cache instance to the Reddit API functions. It also adds theincrementmethod to theICacheandRedisCacheinterfaces and classes, and theRateLimiterandhandleRateLimitmodules to theservices/libs/redisandservices/libs/integrationspackages respectively.
🤖 Generated by Copilot at 5ba51d7
Why
How
🤖 Generated by Copilot at 5ba51d7
globalCacheproperty toIProcessStreamContextinterface and pass it toprocessStreamfunction inintegrationStreamService.ts(link, link, link)handleRateLimit.tsmodule to exportgetRateLimiterfunction that returns a configuredRateLimiterinstance usingglobalCacheand Reddit API parameters (link)getRateLimiterfunction and use it to create a localrateLimitervariable in each Reddit API function (getComments,getMoreComments,getPosts) inintegrations/reddit/apidirectory (link, link, link, link, link, link)checkRateLimitandincrementRateLimitmethods ofrateLimitervariable before and after making a Reddit API request in each Reddit API function (getComments,getMoreComments,getPosts) inintegrations/reddit/apidirectory (link, link, link, link, link, link)RateLimiterclass toservices/libs/redis/srcdirectory that implements the rate limiting logic usingRedisCacheand rate limit parameters (link)RateLimiterclass fromservices/libs/redis/src/index.tsand import it inhandleRateLimit.tsmodule (link)incrementmethod toRedisCacheclass inservices/libs/redis/src/cache.tsandICacheinterface inservices/libs/types/src/caching.tsthat increments a cache value by a given amount and sets an expiration time (link, link)@crowd/redispackage toservices/libs/integrationspackage (link, link, link, link, link)@crowd/redispackage todependenciesandnode_modulessections ofservices/libs/integrations/package-lock.jsonfile (link, link, link, link)@crowd/redispackage todependenciessection ofservices/libs/integrations/package.jsonfile (link)Checklist ✅
Feature,Improvement, orBug.