Profiles: Don't pull files needlessly
This commit is contained in:
parent
0dab6f14a9
commit
e9b9a83042
|
@ -29,9 +29,7 @@ impl Action for CreateSubmission {
|
|||
}
|
||||
|
||||
for file in &self.files {
|
||||
if let Ok(Some(file)) = ctx.store.files.by_id(*file) {
|
||||
changes.add_file(&file);
|
||||
}
|
||||
changes.add_file(*file);
|
||||
}
|
||||
|
||||
let submission = if changes.any_changes() {
|
||||
|
@ -129,33 +127,25 @@ impl Action for UpdateSubmission {
|
|||
let mut removed_file_ids = HashSet::new();
|
||||
if let Some(files) = &self.only_files {
|
||||
for file in submission.files() {
|
||||
if let Ok(Some(file)) = ctx.store.files.by_id(*file) {
|
||||
changes.delete_file(&file);
|
||||
removed_file_ids.insert(file.id());
|
||||
}
|
||||
changes.delete_file(*file);
|
||||
removed_file_ids.insert(*file);
|
||||
}
|
||||
|
||||
for file in files {
|
||||
if let Ok(Some(file)) = ctx.store.files.by_id(*file) {
|
||||
changes.add_file(&file);
|
||||
removed_file_ids.remove(&file.id());
|
||||
}
|
||||
changes.add_file(*file);
|
||||
removed_file_ids.remove(file);
|
||||
}
|
||||
} else {
|
||||
if let Some(removed) = &self.removed_files {
|
||||
for file in removed {
|
||||
if let Ok(Some(file)) = ctx.store.files.by_id(*file) {
|
||||
changes.delete_file(&file);
|
||||
removed_file_ids.insert(file.id());
|
||||
}
|
||||
changes.delete_file(*file);
|
||||
removed_file_ids.insert(*file);
|
||||
}
|
||||
}
|
||||
if let Some(new) = &self.new_files {
|
||||
for file in new {
|
||||
if let Ok(Some(file)) = ctx.store.files.by_id(*file) {
|
||||
changes.add_file(&file);
|
||||
removed_file_ids.remove(&file.id());
|
||||
}
|
||||
changes.add_file(*file);
|
||||
removed_file_ids.remove(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use super::{File, StoreError, Undo};
|
||||
use super::{StoreError, Undo};
|
||||
use chrono::{DateTime, Utc};
|
||||
use sled::{Db, Transactional, Tree};
|
||||
use std::{fmt, io::Cursor};
|
||||
|
@ -226,13 +226,13 @@ impl SubmissionChanges {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn add_file(&mut self, file: &File) -> &mut Self {
|
||||
self.files.push(file.id);
|
||||
pub(crate) fn add_file(&mut self, file_id: Uuid) -> &mut Self {
|
||||
self.files.push(file_id);
|
||||
self
|
||||
}
|
||||
|
||||
pub(crate) fn delete_file(&mut self, file: &File) -> &mut Self {
|
||||
self.files.retain(|id| *id != file.id);
|
||||
pub(crate) fn delete_file(&mut self, file_id: Uuid) -> &mut Self {
|
||||
self.files.retain(|id| *id != file_id);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue