-
-
Notifications
You must be signed in to change notification settings - Fork 180
fix: don't remove timeouts when a member leaves a server #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,13 +169,35 @@ impl AbstractServerMembers for ReferenceDb { | |
} | ||
} | ||
|
||
/// Soft delete a member | ||
async fn soft_delete_member(&self, id: &MemberCompositeKey) -> Result<()> { | ||
let mut server_members = self.server_members.lock().await; | ||
|
||
let member = server_members.get_mut(id); | ||
if let Some(member) = member { | ||
if member.in_timeout() { | ||
panic!("Soft deletion is not implemented.") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing impl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Impl not possible without modifying the member object since the reference db uses members directly. |
||
} else if server_members.remove(id).is_some() { | ||
Ok(()) | ||
} else { | ||
Err(create_error!(NotFound)) | ||
} | ||
} else { | ||
Err(create_error!(NotFound)) | ||
} | ||
} | ||
|
||
/// Delete a server member by their id | ||
async fn delete_member(&self, id: &MemberCompositeKey) -> Result<()> { | ||
async fn force_delete_member(&self, id: &MemberCompositeKey) -> Result<()> { | ||
let mut server_members = self.server_members.lock().await; | ||
if server_members.remove(id).is_some() { | ||
Ok(()) | ||
} else { | ||
Err(create_error!(NotFound)) | ||
} | ||
} | ||
|
||
async fn remove_dangling_members(&self) -> Result<()> { | ||
todo!() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing impl. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Impl not possible without modifying the member object since the reference db uses members directly. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ auto_derived!( | |
Avatar, | ||
Roles, | ||
Timeout, | ||
JoinedAt, | ||
} | ||
|
||
/// Member removal intention | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod file_deletion; | ||
pub mod prune_dangling_files; | ||
pub mod prune_members; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use std::time::Duration; | ||
|
||
use log::warn; | ||
use revolt_database::Database; | ||
use revolt_result::Result; | ||
use tokio::time::sleep; | ||
|
||
pub async fn task(db: Database) -> Result<()> { | ||
loop { | ||
let success = db.remove_dangling_members().await; | ||
if let Err(s) = success { | ||
revolt_config::capture_error(&s); | ||
warn!("Failed to prune dangling members: {:?}", &s); | ||
} | ||
|
||
sleep(Duration::from_secs(90)).await; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For clarity, I think we should change the comment / rename the function here.
Specifically, something such as
insert_or_merge_member
, with the commentInsert a new server member (or use the existing member if one is found)