<commit_before>package no.asgari.civilization.server.action;

import com.mongodb.DB;
import lombok.extern.log4j.Log4j;
import no.asgari.civilization.server.model.Chat;
import no.asgari.civilization.server.model.GameLog;
import no.asgari.civilization.server.model.PBF;
import org.mongojack.DBQuery;
import org.mongojack.JacksonDBCollection;

import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

@Log4j
public class AdminAction extends BaseAction {

    private final JacksonDBCollection<Chat, String> chatCollection;
    private final JacksonDBCollection<GameLog, String> gameLogCollection;
    private final JacksonDBCollection<PBF, String> pbfCollection;

    public AdminAction(DB db) {
        super(db);
        this.pbfCollection = JacksonDBCollection.wrap(db.getCollection(PBF.COL_NAME), PBF.class, String.class);
        this.chatCollection = JacksonDBCollection.wrap(db.getCollection(Chat.COL_NAME), Chat.class, String.class);
        this.gameLogCollection = JacksonDBCollection.wrap(db.getCollection(GameLog.COL_NAME), GameLog.class, String.class);
    }

    public void cleanup() {
        log.info("Running cleanup. Finding all aborted games, chat and gamelogs from old deleted games");

        List<PBF> abortedGames = pbfCollection.find(DBQuery.is("active", false).notExists("winner")).toArray();
        log.info("Found " + abortedGames.size() + " aborted games. Deleting those.");
        //abortedGames.forEach(pbf -> pbfCollection.removeById(pbf.getId()));

        List<GameLog> allLogs = gameLogCollection.find().toArray();
        List<Chat> allChats = chatCollection.find().toArray();

        List<String> allGames = pbfCollection.find().toArray().stream().map(PBF::getId).collect(toList());

        log.info("Before deleting, size of all game logs is " + allLogs.size());
        allLogs.stream()
                .filter(gl -> !allGames.contains(gl.getPbfId()))
                .forEach(gamelog -> gameLogCollection.removeById(gamelog.getId()));
        log.info("After deleting, size of gamelog is " + gameLogCollection.find().length());


        log.info("Before deleting chat size is " + allChats.size());
        allChats.stream()
                .filter(gl -> !allGames.contains(gl.getPbfId()))
                .forEach(chat -> chatCollection.removeById(chat.getId()));
<commit_msg>Changing query<commit_after>package no.asgari.civilization.server.action;

import com.mongodb.DB;
import lombok.extern.log4j.Log4j;
import no.asgari.civilization.server.model.Chat;
import no.asgari.civilization.server.model.GameLog;
import no.asgari.civilization.server.model.PBF;
import org.mongojack.DBQuery;
import org.mongojack.JacksonDBCollection;

import java.util.List;
import java.util.Set;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;

@Log4j
public class AdminAction extends BaseAction {

    private final JacksonDBCollection<Chat, String> chatCollection;
    private final JacksonDBCollection<GameLog, String> gameLogCollection;
    private final JacksonDBCollection<PBF, String> pbfCollection;

    public AdminAction(DB db) {
        super(db);
        this.pbfCollection = JacksonDBCollection.wrap(db.getCollection(PBF.COL_NAME), PBF.class, String.class);
        this.chatCollection = JacksonDBCollection.wrap(db.getCollection(Chat.COL_NAME), Chat.class, String.class);
        this.gameLogCollection = JacksonDBCollection.wrap(db.getCollection(GameLog.COL_NAME), GameLog.class, String.class);
    }

    public void cleanup() {
        log.info("Running cleanup. Finding all aborted games, chat and gamelogs from old deleted games");

        List<PBF> abortedGames = pbfCollection.find(DBQuery.is("active", false).is("winner", null)).toArray();
        log.info("Found " + abortedGames.size() + " aborted games. Deleting those.");
        //abortedGames.forEach(pbf -> pbfCollection.removeById(pbf.getId()));

        List<GameLog> allLogs = gameLogCollection.find().toArray();
        List<Chat> allChats = chatCollection.find().toArray();

        List<String> allGames = pbfCollection.find().toArray().stream().map(PBF::getId).collect(toList());

        log.info("Before deleting, size of all game logs is " + allLogs.size());
        allLogs.stream()
                .filter(gl -> !allGames.contains(gl.getPbfId()))
                .forEach(gamelog -> gameLogCollection.removeById(gamelog.getId()));
        log.info("After deleting, size of gamelog is " + gameLogCollection.find().length());


        log.info("Before deleting chat size is " + allChats.size());
        allChats.stream()
                .filter(gl -> !allGames.contains(gl.getPbfId()))
                .forEach(chat -> chatCollection.removeById(chat.getId()));

{'fraction_non_alphanumeric': 0.12936046511627908, 'fraction_numerical': 0.0012458471760797341, 'mean_word_length': 3.8509566968781472, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5936782', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1438, 'n_words': 266}