Skip to content

Commit 14676fe

Browse files
committed
source-monday: refactors board items fetching and cursor handling
Simplifies the logic for fetching items from boards by removing the iterator class, consolidating the process into standalone async functions, and clarifying error handling for invalid inputs. Fixes a bug in cursor collection to support both board-level and next-page cursors, enhancing reliability and maintainability of pagination. Removes unused logic related to tracking the oldest updated board, focusing on streamlined item retrieval.
1 parent 6140202 commit 14676fe

File tree

5 files changed

+131
-173
lines changed

5 files changed

+131
-173
lines changed

source-monday/source_monday/api.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
fetch_boards_minimal,
1313
fetch_boards_paginated,
1414
fetch_items_by_id,
15-
BoardItemIterator,
15+
get_items_from_boards,
1616
)
1717
from source_monday.models import (
1818
FullRefreshResource,
@@ -273,12 +273,12 @@ async def fetch_items_changes(
273273
},
274274
)
275275

276-
item_iterator = BoardItemIterator(http, log)
277-
278276
while True:
279-
items_generator, get_board_cursor = await item_iterator.get_items_from_boards(list(board_ids_to_backfill))
280-
281-
async for item in items_generator:
277+
async for item in get_items_from_boards(
278+
http,
279+
log,
280+
list(board_ids_to_backfill),
281+
):
282282
if window_start <= item.updated_at <= window_end:
283283
if item.state == "deleted":
284284
item.meta_ = Item.Meta(op="d")
@@ -289,18 +289,6 @@ async def fetch_items_changes(
289289
docs_emitted += 1
290290
yield item
291291

292-
board_cursor = get_board_cursor()
293-
294-
if not board_cursor:
295-
log.debug(
296-
f"No more items to fetch for {len(board_ids_to_backfill)} boards",
297-
{
298-
"board_ids": list(board_ids_to_backfill),
299-
"board_cursor": board_cursor,
300-
},
301-
)
302-
break
303-
304292
if docs_emitted > 0:
305293
yield max_updated_at_in_window + timedelta(seconds=1)
306294
else:

source-monday/source_monday/graphql/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
TEAMS,
1313
USERS,
1414
)
15-
from .items import fetch_items_by_id, BoardItemIterator
15+
from .items import fetch_items_by_id, get_items_from_boards
1616
from .query_executor import execute_query
1717

1818
__all__ = [
@@ -28,5 +28,5 @@
2828
"fetch_boards_paginated",
2929
"fetch_boards_with_retry",
3030
"fetch_items_by_id",
31-
"BoardItemIterator",
31+
"get_items_from_boards",
3232
]

source-monday/source_monday/graphql/boards.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,18 @@ async def fetch_boards_minimal(
5151
log: Logger,
5252
) -> AsyncGenerator[Board, None]:
5353
query = """
54-
query ($limit: Int = 500, $page: Int = 1, $state: State = all) {
54+
query ($limit: Int = 10000, $page: Int = 1, $state: State = all) {
5555
boards(limit: $limit, page: $page, state: $state, order_by: created_at) {
5656
id
5757
name
5858
state
5959
updated_at
60-
items_count
6160
}
6261
}
6362
"""
6463

6564
page = 1
66-
limit = 500
65+
limit = 10000
6766

6867
while True:
6968
variables = {

0 commit comments

Comments
 (0)