Skip to content

Commit

Permalink
Optimized similar images loading
Browse files Browse the repository at this point in the history
  • Loading branch information
Futsch1 committed Jan 6, 2022
1 parent eb2adf2 commit 37b6dc6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ All notable changes to this project will be documented in this file.
### Changed

- Now reading EXIF files for all image formats, not only for JPEGs
- Optimized loading of similar images

### Added

-
- Added filters for the item list

### Fixed

Expand Down
5 changes: 3 additions & 2 deletions src/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,10 @@ fn synchronize_images_model(
model_index += 1;
};

// TODO: Also first item should be loaded in background, but in a prioritized queue
add_item(&selected_item_index, true, window.clone());
// Clear pending commands in the image cache
image_cache.purge();

add_item(&selected_item_index, true, window.clone());
for image_index in similars {
add_item(image_index, false, window.clone());
}
Expand Down
8 changes: 7 additions & 1 deletion src/misc/image_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ impl ImageCache {
)
}

/// Purge all running commands
pub fn purge(&self) {
self.primary_queue.lock().unwrap().clear();
self.secondary_queue.lock().unwrap().clear();
}

/// Sets the maximum width and height of the images to load
pub fn restrict_size(&mut self, max_width: u32, max_height: u32) {
if max_width > self.max_width || max_height > self.max_height {
Expand Down Expand Up @@ -130,7 +136,7 @@ impl ImageCache {
}
Purpose::SimilarImage => {
let mut queue = self.secondary_queue.lock().unwrap();
queue.push_front(command);
queue.push_back(command);
self.secondary_sender.send(()).ok();
}
Purpose::Prefetch => {
Expand Down

0 comments on commit 37b6dc6

Please sign in to comment.