Remove show_emails argument from prefetch_should_download() (#4064)

IIRC, this was written this way back when we didn't have config caching,
in order to save database accesses by getting the config outside the
for loop.
This commit is contained in:
Hocuri
2023-02-20 19:06:43 +01:00
committed by GitHub
parent 56d10f7c42
commit 710cec1beb
2 changed files with 9 additions and 14 deletions

View File

@@ -728,8 +728,6 @@ impl Imap {
};
let read_cnt = msgs.len();
let show_emails = ShowEmails::from_i32(context.get_config_int(Config::ShowEmails).await?)
.unwrap_or_default();
let download_limit = context.download_limit().await?;
let mut uids_fetch = Vec::<(_, bool /* partially? */)>::with_capacity(msgs.len() + 1);
let mut uid_message_ids = BTreeMap::new();
@@ -778,7 +776,6 @@ impl Imap {
&headers,
&message_id,
fetch_response.flags(),
show_emails,
)
.await.context("prefetch_should_download")?
{
@@ -2055,7 +2052,6 @@ pub(crate) async fn prefetch_should_download(
headers: &[mailparse::MailHeader<'_>],
message_id: &str,
mut flags: impl Iterator<Item = Flag<'_>>,
show_emails: ShowEmails,
) -> Result<bool> {
if message::rfc724_mid_exists(context, message_id)
.await?
@@ -2115,6 +2111,9 @@ pub(crate) async fn prefetch_should_download(
})
.unwrap_or_default();
let show_emails =
ShowEmails::from_i32(context.get_config_int(Config::ShowEmails).await?).unwrap_or_default();
let show = is_autocrypt_setup_message
|| match show_emails {
ShowEmails::Off => is_chat_message || is_reply_to_chat_message,

View File

@@ -5,7 +5,7 @@ use crate::aheader::EncryptPreference;
use crate::chat::get_chat_contacts;
use crate::chat::{get_chat_msgs, ChatItem, ChatVisibility};
use crate::chatlist::Chatlist;
use crate::constants::{ShowEmails, DC_GCL_NO_SPECIALS};
use crate::constants::DC_GCL_NO_SPECIALS;
use crate::imap::prefetch_should_download;
use crate::message::Message;
use crate::test_utils::{get_chat_msg, TestContext, TestContextManager};
@@ -647,15 +647,11 @@ async fn test_parse_ndn(
// Check that the ndn would be downloaded:
let headers = mailparse::parse_mail(raw_ndn).unwrap().headers;
assert!(prefetch_should_download(
&t,
&headers,
"some-other-message-id",
std::iter::empty(),
ShowEmails::Off,
)
.await
.unwrap());
assert!(
prefetch_should_download(&t, &headers, "some-other-message-id", std::iter::empty(),)
.await
.unwrap()
);
receive_imf(&t, raw_ndn, false).await.unwrap();
let msg = Message::load_from_db(&t, msg_id).await.unwrap();