mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-02-12 15:02:52 +08: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.mail.Mail;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
|
|
||||||
|
import static com.mongodb.client.model.Filters.eq;
|
||||||
|
|
||||||
public final class DatabaseHelper {
|
public final class DatabaseHelper {
|
||||||
public static Account createAccount(String username) {
|
public static Account createAccount(String username) {
|
||||||
return createAccountWithId(username, 0);
|
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
|
// 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 ...
|
// database in an inconsistent state, but unfortunately Mongo only supports that when we have a replica set ...
|
||||||
|
|
||||||
// Delete mails, gacha records, items and avatars.
|
// Delete Mail.class data
|
||||||
DatabaseManager.getDatastore().find(Mail.class).filter(Filters.eq("ownerUid", target.getPlayerUid())).delete();
|
DatabaseManager.getDatabase().getCollection("mail").deleteMany(eq("ownerUid", target.getPlayerUid()));
|
||||||
DatabaseManager.getDatastore().find(GachaRecord.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
// Delete Avatar.class data
|
||||||
DatabaseManager.getDatastore().find(GameItem.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
DatabaseManager.getDatabase().getCollection("avatars").deleteMany(eq("ownerId", target.getPlayerUid()));
|
||||||
DatabaseManager.getDatastore().find(Avatar.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
// 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.
|
// Delete friendships.
|
||||||
// Here, we need to make sure to not only delete the deleted account's 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.
|
// but also all friendship entries for that account's friends.
|
||||||
DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("ownerId", target.getPlayerUid())).delete();
|
DatabaseManager.getDatabase().getCollection("friendships").deleteMany(eq("ownerId", target.getPlayerUid()));
|
||||||
DatabaseManager.getDatastore().find(Friendship.class).filter(Filters.eq("friendId", target.getPlayerUid())).delete();
|
DatabaseManager.getDatabase().getCollection("friendships").deleteMany(eq("friendId", target.getPlayerUid()));
|
||||||
|
|
||||||
// Delete the player.
|
// Delete the player.
|
||||||
DatabaseManager.getDatastore().find(Player.class).filter(Filters.eq("id", target.getPlayerUid())).delete();
|
DatabaseManager.getDatastore().find(Player.class).filter(Filters.eq("id", target.getPlayerUid())).delete();
|
||||||
|
Loading…
Reference in New Issue
Block a user