def clear_user_permission_cache_for_org( cls, user: github_types.GitHubAccount) -> None: with utils.get_redis_for_cache() as redis: # type: ignore for key in redis.scan_iter( f"{cls.USERS_PERMISSION_CACHE_KEY_PREFIX}{cls.USERS_PERMISSION_CACHE_KEY_DELIMITER}{user['id']}{cls.USERS_PERMISSION_CACHE_KEY_DELIMITER}*" ): redis.delete(key)
def clear_user_permission_cache_for_repo( cls, owner: github_types.GitHubAccount, repo: github_types.GitHubRepository, ) -> None: with utils.get_redis_for_cache() as redis: # type: ignore redis.delete(cls._users_permission_cache_key_for_repo(owner, repo))
def _save_cached_last_summary_head_sha(self, sha): # NOTE(sileht): We store it only for 1 month, if we lose it it's not a big deal, as it's just # to avoid race conditions when too many synchronize events occur in a short period of time with utils.get_redis_for_cache() as redis: redis.set( self.redis_last_summary_head_sha_key(self.pull), sha, ex=SUMMARY_SHA_EXPIRATION, )
def get_cached_last_summary_head_sha_from_pull( cls, pull: dict, ) -> str: with utils.get_redis_for_cache() as redis: # type: ignore # FIXME(jd): remove in January 2021 # Look for old format ################ owner = pull["base"]["repo"]["owner"]["id"] repo = pull["base"]["repo"]["id"] pull_number = pull["number"] for k in redis.keys(f"summary-sha~*~{owner}~{repo}~{pull_number}"): return redis.get(k) # ENDOF FIXME(jd) return redis.get(cls.redis_last_summary_head_sha_key(pull))
def has_write_permission(self, user: github_types.GitHubAccount) -> bool: with utils.get_redis_for_cache() as redis: # type: ignore key = self._users_permission_cache_key permission = redis.hget(key, user["id"]) if permission is None: permission = self.client.item( f"{self.base_url}/collaborators/{user['login']}/permission" )["permission"] with redis.pipeline() as pipe: pipe.hset(key, user["id"], permission) pipe.expire(key, self.USER_PERMISSION_EXPIRATION) pipe.execute() return permission in ( "admin", "maintain", "write", )
def clear_cached_last_summary_head_sha(self): with utils.get_redis_for_cache() as redis: redis.delete(self.redis_last_summary_head_sha_key(self.pull))
def clear_cached_last_summary_head_sha(self) -> None: with utils.get_redis_for_cache( ) as redis: # type: ignore[attr-defined] redis.delete(self.redis_last_summary_head_sha_key(self.pull))