Skip to content

Commit

Permalink
More #notests
Browse files Browse the repository at this point in the history
  • Loading branch information
squeaky-pl committed Aug 26, 2024
1 parent d465de2 commit d403e61
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions bin/block-stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,52 @@
import logging

import click
from sqlalchemy.orm import joinedload

from inbox.logging import configure_logging, get_logger
from inbox.models.block import Block
from inbox.models.session import global_session_scope
from inbox.util import blockstore

configure_logging(logging.INFO)
configure_logging(logging.ERROR)
log = get_logger()


@click.command()
@click.option("--limit", type=int, default=1000)
def run(limit: int) -> None:
@click.option("--after", type=str, default="2024-08-19")
def run(limit: int, after: str) -> None:
with global_session_scope() as db_session:
blocks = (
(
db_session.query(Block)
.options(joinedload(Block.parts))
.filter(
Block.size > 0, Block.updated_at >= datetime.datetime(2024, 8, 19)
Block.size > 0,
Block.updated_at >= datetime.datetime.fromisoformat(after),
)
.order_by(Block.updated_at.desc())
)
.limit(limit)
.all()
)

total_objects = 0
total_size = 0
for block in blocks:
data = blockstore.get_from_blockstore(block.data_sha256)
print(block.data_sha256, block.filename, len(data) if data else None)
print(
block.data_sha256,
block.filename,
block.size if data else None,
[(part.content_disposition, part.message_id) for part in block.parts],
)

if data:
total_objects += 1
total_size += block.size

print(f"Total objects: {total_objects}, total size: {total_size}")


if __name__ == "__main__":
Expand Down

0 comments on commit d403e61

Please sign in to comment.