feat: Remove hidden relays automatically#8402
Conversation
|
There's one open question: #8384 (comment) CI fails due to: #8403 |
921c5df to
1b3f434
Compare
1b3f434 to
a0c7c59
Compare
Hocuri
left a comment
There was a problem hiding this comment.
Looks good, only some minor things.
3607f29 to
967d87f
Compare
Automatically remove relays that are hidden (`is_published=0`) and haven't been used to receive new messages for over 90 days. Closes: #8384 Signed-off-by: Jagoda Ślązak <jslazak@jslazak.com>
967d87f to
c18ac54
Compare
| /// so that we don't cause extra messages to the corresponding inbox, | ||
| /// but can still receive messages from contacts who don't know our new transport addresses yet. | ||
| /// | ||
| /// Unpublished transports that are not used to receive any new messages for 90 days |
There was a problem hiding this comment.
| /// Unpublished transports that are not used to receive any new messages for 90 days | |
| /// Unpublished transports that are not used to receive any new messages for [`crate::sql::HIDDEN_TRANSPORT_CLEANUP_TIME`] |
| .context("add_parts error")? | ||
| }; | ||
|
|
||
| // NOTE: this is called only for first transport that receives a message. |
There was a problem hiding this comment.
| // NOTE: this is called only for first transport that receives a message. | |
| // NOTE: normally this only updates the first transport that receives a message. |
It's not actually "called" for the first transport, and it can update multiple transports if receive_imf failed previously for the same message received from another transport.
Btw, why not do this from imap right before receive_imf_inner() where we also know the transport id? Currently if an error happens before this place, we don't update transport's timestamp, but it doesn't mean that we don't use the transport to receive the message, moreover, the message may have useful side effects.
| // it's safe to assume that the hidden transport can be safely removed. | ||
| sql::update_transport_last_rcvd_timestamp(context, rfc724_mid) | ||
| .await | ||
| .context("Failed to update transport's last_rcvd_timestamp value.")?; |
There was a problem hiding this comment.
| .context("Failed to update transport's last_rcvd_timestamp value.")?; | |
| .context("Failed to update transport's last_rcvd_timestamp value")?; |
There was a problem hiding this comment.
The reason for not adding a point here is that if you add a point here, and then log the error with warn!(context, "Something failed: {err:#}"), then there will be two points at the end of the log line. See also https://github.com/chatmail/core/blob/main/STYLE.md#errors
| use pool::{Pool, WalCheckpointStats}; | ||
|
|
||
| /// How long a hidden and unused transport should be kept in the database before being deleted. | ||
| pub const HIDDEN_TRANSPORT_CLEANUP_TIME: i64 = 90 * 24 * 60 * 60; |
There was a problem hiding this comment.
Could be renamed to UNPUBLISHED_TRANSPORT_CLEANUP_TIME for consistency with set_transport_unpublished(). Maybe even to UNPUBLISHED_TRANSPORT_KEEP_TIME or UNPUBLISHED_TRANSPORT_TTL
|
|
||
| /// Removes transports that are hidden (`is_published=0`), | ||
| /// and haven't been used to receive new messages for [`HIDDEN_TRANSPORT_CLEANUP_TIME`] seconds. | ||
| pub async fn remove_unused_hidden_transports(context: &Context) -> Result<usize> { |
There was a problem hiding this comment.
| pub async fn remove_unused_hidden_transports(context: &Context) -> Result<usize> { | |
| pub(crate) async fn remove_unused_hidden_transports(context: &Context) -> Result<usize> { |
| /// | ||
| /// This is used to postpone deletion of hidden transport by [`remove_unused_hidden_transports`], | ||
| /// if it is still used to receive messages. | ||
| pub async fn update_transport_last_rcvd_timestamp( |
There was a problem hiding this comment.
| pub async fn update_transport_last_rcvd_timestamp( | |
| pub(crate) async fn update_transport_last_rcvd_timestamp( |
| "UPDATE transports | ||
| SET last_rcvd_timestamp=?1 | ||
| FROM transports t1 | ||
| INNER JOIN imap ON t1.id=imap.transport_id | ||
| WHERE imap.rfc724_mid=?2", |
There was a problem hiding this comment.
This would seem more readable to me as
UPDATE transports
SET last_rcvd_timestamp = ?1
WHERE id = (
SELECT transport_id FROM imap WHERE imap.rfc724_mid = ?2
)because it wouldn't be necessary to know the UPDATE FROM SQL syntax, and it would be possible to think about the inner and the outer statement separately.
Automatically remove relays that are hidden (
is_published=0) and haven't been used to receive new messages for over 90 days.Closes: #8384