Skip to content

Commit

Permalink
Correct size calculation of row, since it doesn't work with nested dict
Browse files Browse the repository at this point in the history
  • Loading branch information
BryanFauble committed Feb 19, 2025
1 parent f5b49f0 commit 05adca1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions synapseclient/models/mixins/table_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,14 @@ def to_synapse_request(self):
delete_none_keys(result)
return result

def size(self) -> int:
"""Returns the size of the PartialRow in bytes."""
return (
sys.getsizeof(self.values)
+ sys.getsizeof(self.row_id)
+ sys.getsizeof(self.etag)
)


@dataclass
class PartialRowSet:
Expand Down Expand Up @@ -1333,7 +1341,9 @@ class TableUpdateTransaction(AsynchronousCommunicator):
"""

entity_id: str
changes: List[Union[TableSchemaChangeRequest, UploadToTableRequest]]
changes: List[
Union[TableSchemaChangeRequest, UploadToTableRequest, AppendableRowSetRequest]
]
concrete_type: str = concrete_types.TABLE_UPDATE_TRANSACTION_REQUEST
results: Optional[List[Dict[str, Any]]] = None
"""This will be an array of
Expand Down Expand Up @@ -2090,7 +2100,7 @@ async def main():
current_chunk_size = 0
chunk = []
for row in rows_to_update:
row_size = sys.getsizeof(row.to_synapse_request())
row_size = row.size()
if current_chunk_size + row_size > update_size_byte:
change = AppendableRowSetRequest(
entity_id=self.id,
Expand All @@ -2105,12 +2115,6 @@ async def main():
changes=[change],
)

# TODO: Temporary logic for debugging
size_of_request = sys.getsizeof(row.to_synapse_request())
client.logger.info(
f"Updating {len(chunk)} rows with a size of {size_of_request} bytes"
)

await request.send_job_and_wait_async(synapse_client=client)
chunk = []
current_chunk_size = 0
Expand Down

0 comments on commit 05adca1

Please sign in to comment.