def test_chunks_with_empty_iterable(): iterable = [] size = randint(1, 10) chunks = list(utils.chunks(iterable, size)) assert list(chunks) == []
def get_friends_ids_batch(user_ids: Iterable[int]) -> List[List[int]]: user_ids_str = list(map(str, user_ids)) result = [] for chunk in chunks(user_ids_str, 25): response = _authorized_api.execute.friends(targets=chunk) result.extend(response) return result
def get_friends_ids_batch(user_ids: List[int]) -> List[List[int]]: job = group([ tasks.get_friends_ids_batch.s(chunk) for chunk in chunks(user_ids, 75) ]) result = job.apply_async().join() full_result = [] for list_ in result: full_result.extend(list_) return full_result
def test_chunks(): start = randint(0, 1000) end = start + randint(1, 1000) step = randint(1, 10) iterable = list(range(start, end, step)) size = randint(1, 10) chunks = list(utils.chunks(iterable, size)) assert len(chunks) == ceil(len(iterable) / size) assert all(len(chunk) == size for chunk in chunks[:-1]) assert len(chunks[-1]) <= size assert iterable == [item for chunk in chunks for item in chunk]
def get_mutual_friends_ids_batch(user_ids: List[int], my_id: int) -> Dict[int, List[int]]: job = group([ tasks.get_mutual_friends_ids_batch.s(chunk, my_id) for chunk in chunks(user_ids, 75) ]) result = job.apply_async().join() full_result = { int(key): value for dictionary in result for key, value in dictionary.items() } return full_result