mirror of
https://github.com/aljazceru/pubky-core.git
synced 2026-01-01 13:24:20 +01:00
feat(homeserver): add Entry::read_content() method
This commit is contained in:
@@ -1,23 +1,24 @@
|
||||
use heed::{types::Bytes, Database, RoTxn};
|
||||
use pubky_common::timestamp::Timestamp;
|
||||
|
||||
use crate::database::DB;
|
||||
|
||||
/// hash of the blob => bytes.
|
||||
use super::entries::Entry;
|
||||
|
||||
/// (entry timestamp | chunk_index BE) => bytes
|
||||
pub type BlobsTable = Database<Bytes, Bytes>;
|
||||
|
||||
pub const BLOBS_TABLE: &str = "blobs";
|
||||
|
||||
impl DB {
|
||||
pub fn get_blob<'txn>(
|
||||
pub fn read_entry_content<'txn>(
|
||||
&self,
|
||||
rtxn: &'txn RoTxn,
|
||||
timestamp: &Timestamp,
|
||||
entry: &Entry,
|
||||
) -> anyhow::Result<impl Iterator<Item = Result<&'txn [u8], heed::Error>> + 'txn> {
|
||||
Ok(self
|
||||
.tables
|
||||
.blobs
|
||||
.prefix_iter(rtxn, ×tamp.to_bytes())?
|
||||
.prefix_iter(rtxn, &entry.timestamp().to_bytes())?
|
||||
.map(|i| i.map(|(_, bytes)| bytes)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,6 +291,14 @@ impl Entry {
|
||||
|
||||
// === Public Method ===
|
||||
|
||||
pub fn read_content<'txn>(
|
||||
&self,
|
||||
db: &'txn DB,
|
||||
rtxn: &'txn RoTxn,
|
||||
) -> anyhow::Result<impl Iterator<Item = Result<&'txn [u8], heed::Error>> + 'txn> {
|
||||
db.read_entry_content(rtxn, self)
|
||||
}
|
||||
|
||||
pub fn serialize(&self) -> Vec<u8> {
|
||||
to_allocvec(self).expect("Session::serialize")
|
||||
}
|
||||
@@ -464,7 +472,7 @@ mod tests {
|
||||
let mut blob = vec![];
|
||||
|
||||
{
|
||||
let mut iter = db.get_blob(&rtxn, entry.timestamp()).unwrap();
|
||||
let mut iter = entry.read_content(&db, &rtxn).unwrap();
|
||||
|
||||
while let Some(Ok(chunk)) = iter.next() {
|
||||
blob.extend_from_slice(&chunk);
|
||||
@@ -504,7 +512,7 @@ mod tests {
|
||||
let mut blob = vec![];
|
||||
|
||||
{
|
||||
let mut iter = db.get_blob(&rtxn, entry.timestamp()).unwrap();
|
||||
let mut iter = entry.read_content(&db, &rtxn).unwrap();
|
||||
|
||||
while let Some(Ok(chunk)) = iter.next() {
|
||||
blob.extend_from_slice(&chunk);
|
||||
|
||||
@@ -93,7 +93,7 @@ pub async fn get(
|
||||
let option = state.db.get_entry(&rtxn, &public_key, &path)?;
|
||||
|
||||
if let Some(entry) = option {
|
||||
let iter = state.db.get_blob(&rtxn, entry.timestamp())?;
|
||||
let iter = entry.read_content(&state.db, &rtxn)?;
|
||||
|
||||
entry_tx.send(Some(entry))?;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user