MCPcopy Create free account
hub / github.com/chatmail/core / remove_unused_files

Function remove_unused_files

src/sql.rs:927–1092  ·  view source on GitHub ↗
(context: &Context)

Source from the content-addressed store, hash-verified

925/// Enumerates used files in the blobdir and removes unused ones.
926#[expect(clippy::arithmetic_side_effects)]
927pub async fn remove_unused_files(context: &Context) -> Result<()> {
928 let mut files_in_use = HashSet::new();
929 let mut unreferenced_count = 0;
930
931 info!(context, "Start housekeeping...");
932 maybe_add_from_param(
933 &context.sql,
934 &mut files_in_use,
935 "SELECT param FROM msgs WHERE chat_id!=3 AND type!=10;",
936 Param::File,
937 )
938 .await?;
939 maybe_add_from_param(
940 &context.sql,
941 &mut files_in_use,
942 "SELECT param FROM chats;",
943 Param::ProfileImage,
944 )
945 .await?;
946 maybe_add_from_param(
947 &context.sql,
948 &mut files_in_use,
949 "SELECT param FROM contacts;",
950 Param::ProfileImage,
951 )
952 .await?;
953
954 context
955 .sql
956 .query_map(
957 "SELECT value FROM config;",
958 (),
959 |row| {
960 let row: String = row.get(0)?;
961 Ok(row)
962 },
963 |rows| {
964 for row in rows {
965 maybe_add_file(&mut files_in_use, &row?);
966 }
967 Ok(())
968 },
969 )
970 .await
971 .context("housekeeping: failed to SELECT value FROM config")?;
972
973 context
974 .sql
975 .query_map(
976 "SELECT blobname FROM http_cache",
977 (),
978 |row| {
979 let row: String = row.get(0)?;
980 Ok(row)
981 },
982 |rows| {
983 for row in rows {
984 maybe_add_file(&mut files_in_use, &row?);

Callers 1

housekeepingFunction · 0.85

Calls 8

maybe_add_from_paramFunction · 0.85
maybe_add_fileFunction · 0.85
read_dirFunction · 0.85
is_file_in_useFunction · 0.85
delete_fileFunction · 0.85
query_mapMethod · 0.80
getMethod · 0.45
get_blobdirMethod · 0.45

Tested by

no test coverage detected