mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
include mxcs from dangling thumbnails in service::media::iter_all
When requesting remote thumbnails over federation, we can end up with a thumbnail in the media db without an associated original file. Because of this, skipping thumbnails is insufficient to get a list of all MXCs.
This commit is contained in:
parent
230192be1b
commit
916088a22f
3 changed files with 19 additions and 10 deletions
|
|
@ -169,11 +169,27 @@ impl Service {
|
|||
|
||||
/// List all media stored in the database.
|
||||
///
|
||||
/// Each MXC is list once. Thumbnails are not included separately from the
|
||||
/// Each MXC is listed once. Thumbnails are not included separately from the
|
||||
/// original media.
|
||||
#[tracing::instrument(skip(self))]
|
||||
pub(crate) fn iter_all(&self) -> impl Iterator<Item = Result<OwnedMxcUri>> {
|
||||
self.db.all_file_metadata().map(|media| media.map(|(mxc, ..)| mxc))
|
||||
let mut prev_mxc = None;
|
||||
self.db
|
||||
.all_file_metadata()
|
||||
.map(|media| media.map(|(mxc, ..)| mxc))
|
||||
.filter(move |mxc| {
|
||||
if let Ok(mxc) = mxc {
|
||||
// Skip mxcs that we have already seen. All files associated
|
||||
// with a given mxc should appear consecutively in the db
|
||||
// iterator, so we only need to check against the previous
|
||||
// value.
|
||||
if prev_mxc.as_ref() == Some(mxc) {
|
||||
return false;
|
||||
}
|
||||
prev_mxc = Some(mxc.clone());
|
||||
}
|
||||
true
|
||||
})
|
||||
}
|
||||
|
||||
/// Returns width, height of the thumbnail and whether it should be cropped.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue