Skip to content

Commit 24f684b

Browse files
Merge pull request #419 from adamtheturtle/has-children
Reduce API calls by using has_children
2 parents 5f91155 + 75b02cc commit 24f684b

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/_notion_scripts/upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def _block_without_children(
4141
Return a copy of a block without children.
4242
"""
4343
serialized_block = block.obj_ref.serialize_for_api()
44-
if block.blocks:
44+
if block.has_children:
4545
serialized_block[serialized_block["type"]]["children"] = []
4646

4747
# Delete the ID, else the block will have the children from Notion.
@@ -243,7 +243,7 @@ def _block_with_uploaded_file(*, block: Block, session: Session) -> Block:
243243

244244
block = block.__class__(file=uploaded_file, caption=block.caption)
245245

246-
elif isinstance(block, ParentBlock) and block.blocks:
246+
elif isinstance(block, ParentBlock) and block.has_children:
247247
new_child_blocks = [
248248
_block_with_uploaded_file(block=child_block, session=session)
249249
for child_block in block.blocks

src/sphinx_notion/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ def _serialize_block_with_children(
184184
Convert a block to a JSON-serializable format which includes its children.
185185
"""
186186
serialized_obj = block.obj_ref.serialize_for_api()
187-
if isinstance(block, ParentBlock) and block.blocks:
187+
if isinstance(block, ParentBlock) and block.has_children:
188188
serialized_obj[block.obj_ref.type]["children"] = [
189189
_serialize_block_with_children(block=child)
190190
for child in block.blocks

tests/test_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def _details_from_block(*, block: Block) -> dict[str, Any]:
7575
Create a serialized block details from a Block.
7676
"""
7777
serialized_obj = block.obj_ref.serialize_for_api()
78-
if isinstance(block, ParentBlock) and block.blocks:
78+
if isinstance(block, ParentBlock) and block.has_children:
7979
serialized_obj[block.obj_ref.type]["children"] = [
8080
_details_from_block(block=child) for child in block.blocks
8181
]

0 commit comments

Comments
 (0)