Skip to content
Snippets Groups Projects
Commit a14e6219 authored by Stephen D's avatar Stephen D
Browse files

fix slowdown bug with thousands of images

parent 53b7baaa
No related branches found
No related tags found
No related merge requests found
use image::{imageops::FilterType, io::Reader as ImageReader, ImageOutputFormat};
use std::{cmp::max, fs, io::Cursor, path::PathBuf, sync::mpsc::Receiver};
use std::{cmp::max, collections::HashSet, fs, io::Cursor, path::PathBuf, sync::mpsc::Receiver};
const IMG_MAX_SIZE: u32 = 2048;
const JPEG_QUALITY: u8 = 100; // let ssdv do the compression
......@@ -80,6 +80,7 @@ impl ImgInfo {
pub struct ImgManager {
paths: Vec<PathBuf>,
imgs: Vec<ImgInfo>,
seen_imgs: HashSet<PathBuf>,
// used to receive image requests, which will be sent at full resolution
rx: Receiver<u8>,
......@@ -99,6 +100,7 @@ impl ImgManager {
Self {
paths,
imgs: vec![],
seen_imgs: HashSet::new(),
rx,
iter: 0,
......@@ -230,19 +232,20 @@ impl ImgManager {
// only files
.filter(|(p, _)| p.is_file())
// only new files
.filter(|(p, _)| !self.imgs.iter().any(|i| i.path == p.as_path()))
.filter(|(p, _)| !self.seen_imgs.contains(p))
.collect();
for (path, metadata) in new_imgs {
let size_bytes = metadata.len();
self.imgs.push(ImgInfo {
path,
path: path.clone(),
path_idx: self.path_idx,
size_bytes,
txed: false,
found_on_iter: self.iter,
});
self.seen_imgs.insert(path);
}
Ok(())
......
......@@ -16,7 +16,6 @@ fn main() -> anyhow::Result<()> {
let config = Config::load()?;
let controller = Controller::new(config);
controller.run_forever();
Ok(())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment