Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the unnecessary model_config to reduce the serialized message size #218

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions common/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class TimeBucket(StrictBaseModel):
"""Represents a specific time bucket in the linear flow of time."""

# Makes the object "Immutable" once created.
model_config = ConfigDict(frozen=True)
class Config:
frozen = True

id: PositiveInt = Field(
description="Monotonically increasing value idenitifying the given time bucket"
Expand Down Expand Up @@ -105,7 +106,8 @@ class DataEntity(StrictBaseModel):
"""A logical unit of data that has been scraped. E.g. a Reddit post"""

# Makes the object "Immutable" once created.
model_config = ConfigDict(frozen=True)
class Config:
frozen = True

# Path from which the entity was generated.
uri: str
Expand Down Expand Up @@ -136,7 +138,8 @@ class DataEntityBucketId(StrictBaseModel):
"""Uniquely identifies a bucket to group DataEntities by time bucket, source, and label."""

# Makes the object "Immutable" once created.
model_config = ConfigDict(frozen=True)
class Config:
frozen = True

time_bucket: TimeBucket
source: DataSource = Field()
Expand Down
10 changes: 6 additions & 4 deletions storage/miner/sqlite_miner_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,19 +225,21 @@ def list_data_entities_in_data_entity_bucket(
# If we would go over the max DataEntityBucket size instead return early.
return data_entities
else:
# Add the optional Label field if not null.
label = None
if row["label"] != "NULL":
label = DataLabel(value=row["label"])

# Construct the new DataEntity with all non null columns.
data_entity = DataEntity(
uri=row["uri"],
datetime=row["datetime"],
source=DataSource(row["source"]),
content=row["content"],
content_size_bytes=row["contentSizeBytes"],
label=label,
)

# Add the optional Label field if not null.
if row["label"] != "NULL":
data_entity.label = DataLabel(value=row["label"])

data_entities.append(data_entity)
running_size += row["contentSizeBytes"]

Expand Down
17 changes: 15 additions & 2 deletions tests/common/test_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def serialize_like_dendrite(synapse: bt.Synapse) -> str:

def serialize_like_axon(synapse: bt.Synapse) -> str:
"""Serializes a synapse like an Axon would."""
return serialize_like_dendrite(synapse)
return synapse.json()


def deserialize(json_str: str, cls: Type) -> bt.Synapse:
Expand Down Expand Up @@ -133,7 +133,20 @@ def test_synapse_serialization(self):
# Also check that the headers can be constructed.
request.to_headers()

# TODO: Add a test for the response.
response = request.copy()
response.data_entities = [
DataEntity(
uri=f"http://uri/{i}",
content=b"Hello, world!",
datetime=dt.datetime.utcnow(),
label=DataLabel(value="r/bittensor_"),
source=DataSource.REDDIT,
content_size_bytes=13,
)
for i in range(350_000)
]
response_json = serialize_like_axon(response)
print(len(response_json))


if __name__ == "__main__":
Expand Down
12 changes: 7 additions & 5 deletions tests/storage/miner/test_sqlite_miner_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,15 @@ def test_store_identical_entities(self):
self.test_storage.store_data_entities([entity1, entity2])

# Update the contents
entity1.content = bytes(50)
entity1.content_size_bytes = 50
entity2.content = bytes(100)
entity2.content_size_bytes = 100
entity1_copy = entity1.copy(
update={"content": bytes(50), "content_size_bytes": 50}
)
entity2_copy = entity2.copy(
update={"content": bytes(100), "content_size_bytes": 100}
)

# Store the entities again.
self.test_storage.store_data_entities([entity1, entity2])
self.test_storage.store_data_entities([entity1_copy, entity2_copy])

# Confirm that only one set of entities were stored and the content matches the latest.
with contextlib.closing(self.test_storage._create_connection()) as connection:
Expand Down