mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-27 09:46:21 +00:00
Fixed account delete can not delete all related data (#767)
This commit is contained in:
parent
32154c2a55
commit
bf3d6b3c64
@ -16,6 +16,8 @@ import emu.grasscutter.game.inventory.GameItem;
|
||||
import emu.grasscutter.game.mail.Mail;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
|
||||
import static com.mongodb.client.model.Filters.eq;
|
||||
|
||||
public final class DatabaseHelper {
|
||||
public static Account createAccount(String username) {
|
||||
return createAccountWithId(username, 0);
|
||||
@ -101,17 +103,20 @@ public final class DatabaseHelper {
|
||||
// This should optimally be wrapped inside a transaction, to make sure an error thrown mid-way does not leave the
|
||||
// database in an inconsistent state, but unfortunately Mongo only supports that when we have a replica set ...
|
||||
|
||||
// Delete mails, gacha records, items and avatars.
|
||||
DatabaseManager.getDatastore().find(Mail.class).filter(Filters.eq("ownerUid", target.getPlayerUid())).delete();
|
||||
DatabaseManager.getDatastore().find(GachaRecord.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
||||
DatabaseManager.getDatastore().find(GameItem.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
||||
DatabaseManager.getDatastore().find(Avatar.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
||||
// Delete Mail.class data
|
||||
DatabaseManager.getDatabase().getCollection("mail").deleteMany(eq("ownerUid", target.getPlayerUid()));
|
||||
// Delete Avatar.class data
|
||||
DatabaseManager.getDatabase().getCollection("avatars").deleteMany(eq("ownerId", target.getPlayerUid()));
|
||||
// Delete GachaRecord.class data
|
||||
DatabaseManager.getDatabase().getCollection("gachas").deleteMany(eq("ownerId", target.getPlayerUid()));
|
||||
// Delete GameItem.class data
|
||||
DatabaseManager.getDatabase().getCollection("items").deleteMany(eq("ownerId", target.getPlayerUid()));
|
||||
|
||||
// Delete friendships.
|
||||
// Here, we need to make sure to not only delete the deleted account's friendships,
|
||||
// but also all friendship entries for that account's friends.
|
||||
DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
||||
DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("friendId", target.getPlayerUid())).delete();
|
||||
DatabaseManager.getDatabase().getCollection("friendships").deleteMany(eq("ownerId", target.getPlayerUid()));
|
||||
DatabaseManager.getDatabase().getCollection("friendships").deleteMany(eq("friendId", target.getPlayerUid()));
|
||||
|
||||
// Delete the player.
|
||||
DatabaseManager.getDatastore().find(Player.class).filter(Filters.eq("id", target.getPlayerUid())).delete();
|
||||
|
Loading…
Reference in New Issue
Block a user