mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
media: add MediaFileKey wrapper
One more win in the fight against the Vec<u8>s
This commit is contained in:
parent
84850a163d
commit
1ccb1e572b
5 changed files with 38 additions and 13 deletions
|
|
@ -25,9 +25,10 @@ use ruma::{
|
|||
use tracing::{debug, error, info, info_span, warn, Instrument};
|
||||
|
||||
use crate::{
|
||||
config::DatabaseBackend, observability::FilterReloadHandles,
|
||||
service::rooms::timeline::PduCount, services, utils, Config, Error,
|
||||
PduEvent, Result, Services, SERVICES,
|
||||
config::DatabaseBackend,
|
||||
observability::FilterReloadHandles,
|
||||
service::{media::MediaFileKey, rooms::timeline::PduCount},
|
||||
services, utils, Config, Error, PduEvent, Result, Services, SERVICES,
|
||||
};
|
||||
|
||||
pub(crate) struct KeyValueDatabase {
|
||||
|
|
@ -606,6 +607,7 @@ impl KeyValueDatabase {
|
|||
if services().globals.database_version()? < 3 {
|
||||
// Move media to filesystem
|
||||
for (key, content) in db.mediaid_file.iter() {
|
||||
let key = MediaFileKey::new(key);
|
||||
if content.is_empty() {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -613,7 +615,7 @@ impl KeyValueDatabase {
|
|||
let path = services().globals.get_media_file(&key);
|
||||
let mut file = fs::File::create(path)?;
|
||||
file.write_all(&content)?;
|
||||
db.mediaid_file.insert(&key, &[])?;
|
||||
db.mediaid_file.insert(key.as_bytes(), &[])?;
|
||||
}
|
||||
|
||||
services().globals.bump_database_version(3)?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue