<commit_before>﻿// ==========================================================================
//  Squidex Headless CMS
// ==========================================================================
//  Copyright (c) Squidex UG (haftungsbeschraenkt)
//  All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using Squidex.Infrastructure.Migrations;

namespace Migrate_01.Migrations
{
    public sealed class ConvertRuleEventsJson : IMigration
    {
        private readonly IMongoCollection<BsonDocument> collection;

        public ConvertRuleEventsJson(IMongoDatabase database)
        {
            collection = database.GetCollection<BsonDocument>("RuleEvents");
        }

        public async Task UpdateAsync()
        {
            foreach (var document in collection.Find(new BsonDocument()).ToEnumerable())
            {
                document["Job"]["actionData"] = document["Job"]["actionData"].ToBsonDocument().ToJson();

                await collection.ReplaceOneAsync(Builders<BsonDocument>.Filter.Eq("_id", document["_id"].ToString()), document);
            }
        }
    }
}
<commit_msg>Small code improvement.<commit_after>﻿// ==========================================================================
//  Squidex Headless CMS
// ==========================================================================
//  Copyright (c) Squidex UG (haftungsbeschraenkt)
//  All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.Threading.Tasks;
using MongoDB.Bson;
using MongoDB.Driver;
using Squidex.Infrastructure.Migrations;

namespace Migrate_01.Migrations
{
    public sealed class ConvertRuleEventsJson : IMigration
    {
        private readonly IMongoCollection<BsonDocument> collection;

        public ConvertRuleEventsJson(IMongoDatabase database)
        {
            collection = database.GetCollection<BsonDocument>("RuleEvents");
        }

        public async Task UpdateAsync()
        {
            foreach (var document in collection.Find(new BsonDocument()).ToEnumerable())
            {
                document["Job"]["actionData"] = document["Job"]["actionData"].ToBsonDocument().ToJson();

                var filter = Builders<BsonDocument>.Filter.Eq("_id", document["_id"].ToString());

                await collection.ReplaceOneAsync(filter, document);
            }
        }
    }
}

{'fraction_non_alphanumeric': 0.2640405616224649, 'fraction_numerical': 0.0015600624024961, 'mean_word_length': 3.638336347197107, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '1687487', 'n_tokens_mistral': 628, 'n_tokens_neox': 583, 'n_words': 119}