feat: store message size

This commit is contained in:
Vlad Stan 2023-02-09 15:16:22 +02:00
parent f331a19d75
commit c488f5d5e0
4 changed files with 12 additions and 5 deletions

View file

@ -82,11 +82,12 @@ async def create_event(relay_id: str, e: NostrEvent):
created_at,
kind,
content,
sig
sig,
size
)
VALUES (?, ?, ?, ?, ?, ?, ?)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(relay_id, e.id, e.pubkey, e.created_at, e.kind, e.content, e.sig),
(relay_id, e.id, e.pubkey, e.created_at, e.kind, e.content, e.sig, e.size_bytes),
)
# todo: optimize with bulk insert

View file

@ -28,7 +28,8 @@ async def m001_initial(db):
created_at {db.big_int} NOT NULL,
kind INT NOT NULL,
content TEXT NOT NULL,
sig TEXT NOT NULL
sig TEXT NOT NULL,
size {db.big_int} DEFAULT 0
);
"""
)

View file

@ -116,6 +116,11 @@ class NostrEvent(BaseModel):
id = hashlib.sha256(data.encode()).hexdigest()
return id
@property
def size_bytes(self) -> int:
s = json.dumps(dict(self), separators=(",", ":"), ensure_ascii=False)
return len(s.encode())
def is_replaceable_event(self) -> bool:
return self.kind in [0, 3]

View file

@ -62,7 +62,7 @@
<q-tab-panel name="payment">
<div v-if="relay">
<div class="row items-center no-wrap q-mb-md">
<div class="col-3 q-pr-lg q-pb-md">Free storage:</div>
<div class="col-3 q-pr-lg q-pb-md">Free Storage:</div>
<div class="col-2 q-pr-lg">
<q-input
filled