Skip to content

Commit

Permalink
No File.refresh() during File.append_block (#585)
Browse files Browse the repository at this point in the history
The current code, upon appending a `Block` to a `File`, immediately
calls `File.refresh()` to update the state of the `File` object. This PR
adds the newly created `Block` directly to the `File` without making a
second API call.

The risk / downside to this is that any blocks that were created on the
File in between are now not loaded as part of this call.
  • Loading branch information
dkolas authored Oct 13, 2023
1 parent 08c2585 commit beee58d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/steamship/data/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,15 @@ def append_block(
mime_type=mime_type,
public_data=public_data,
)
self.refresh()
if (
self.blocks is not None
and len(self.blocks) > 0
and block.index_in_file == self.blocks[-1].index_in_file + 1
):
self.blocks.append(block)
else:
self.refresh()

return block

def set_public_data(self, public_data: bool):
Expand Down
3 changes: 3 additions & 0 deletions tests/steamship_tests/data/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def test_append_is_present(client: Steamship):
file.refresh()
assert len(file.blocks) == 2

file.append_block(text="third")
assert len(file.blocks) == 3

my_file = File.create(client, handle="my_file", content="")
assert len(my_file.blocks) == 0
my_file.append_block(text="first")
Expand Down

0 comments on commit beee58d

Please sign in to comment.