<commit_before>namespace :data do

  desc "Set replied_at field for Topic model"
  task set_topic_replied_at: :environment do
    Topic.all.each do |topic|
      if topic.posts.desc(:created_at).first
        topic.replied_at = topic.posts.desc(:created_at).first.created_at
        topic.save
      end
    end
  end

  desc "reset the body_html field of the posts"
  task set_post_body_html: :environment do
    Post.all.each do |post|
      post.body_html = MarkdownConverter.convert(post.body)
      post.save
    end
  end

  desc "add the root node to the node tree"
  task add_root_node: :environment do
    unless Node.where(path: 'root').exists?
      root = Category.new(name: 'root', path: 'root')
      root.save(validate: false)
      Node.all.each do |node|
        unless node.path == 'root'
          puts node.path
          node.parent = root
          node.save(validate: false)
        end
      end
    end
  end

  desc "clear all top posts"
  task clear_all_top_posts: :environment do
    Post.update_all(top: 0)
  end

  desc "change primary key's type to object id"
  task change_to_object_id: :environment do
    class IdGenerator
      include Mongoid::Document
      def self.get_new_object_id
        g = self.create
        g.id
      end
    end

    relation_hash = {
        User => {
            Topic => {
                user_id: 0,
                locker_id: 0,
                unlocker_id: 0,
                deleter_id: 0,
                resumer_id: 0
            },
            Post => {
                author_id: 0,
                mentioned_user_ids: 1,
                deleter_id: 0,
                resumer_id: 0
            },
            Picture => {
                user_id: 0
            },
            Comment => {
                user_id: 0,
                mentioned_user_ids: 1,
                deleter_id: 0,
                resumer_id: 0
            },
            Board => {
                creator_id: 0,
                moderator_ids: 1
            },
            BlockedUser => {
                user_id: 0,
                blocker_id: 0
            },
            Notification::Base => {
                user_id: 0
            },
            Elite::Node => {
                moderator_id: 0,
                deleter_id: 0,
                resumer_id: 0
            },
            Elite::Post => {
                author_id: 0
            }
        },
        Topic => {
            Post => {
                topic_id: 0
            },
            Elite::Post => {
                topic_id: 0
            }
        },
        Post => {
            Comment => {
                commentable: 2
            },
            Post => {
                parent_id: 0
            },
            Notification::PostReply => {
                post_id: 0
            },
            Notification::Mention => {
                mentionable: 2
            },
            Elite::Post => {
                original_id: 0
            }
        },
        Picture => {
        },
        Node => {
            User => {
                managing_board_ids: 1,
                collecting_board_ids: 1
            },
            Topic => {
                board_id: 0
            },
            Post => {
                board_id: 0
            },
            Node => {
                parent_id: 0
            },
            Comment => {
                board_id: 0
            },
            BlockedUser => {
                blockable: 2
            },
            Elite::Node => {
                board_id: 0
            }
        },
        Comment => {
            Comment => {
                commentable: 2
            },
            Notification::Mention => {
                mentionable: 2
            },
            Notification::Comment => {
                comment_id: 0
            }
        },
        BlockedUser => {
        },
        Notification::Base => {
        },
        Elite::Node => {
        }
    }

    relation_hash.each do |klass, relations|
      p '#' + klass.to_s<commit_msg>fix a bug<commit_after>namespace :data do

  desc "Set replied_at field for Topic model"
  task set_topic_replied_at: :environment do
    Topic.all.each do |topic|
      if topic.posts.desc(:created_at).first
        topic.replied_at = topic.posts.desc(:created_at).first.created_at
        topic.save
      end
    end
  end

  desc "reset the body_html field of the posts"
  task set_post_body_html: :environment do
    Post.all.each do |post|
      post.body_html = MarkdownConverter.convert(post.body)
      post.save
    end
  end

  desc "add the root node to the node tree"
  task add_root_node: :environment do
    unless Node.where(path: 'root').exists?
      root = Category.new(name: 'root', path: 'root')
      root.save(validate: false)
      Node.all.each do |node|
        unless node.path == 'root'
          puts node.path
          node.parent = root
          node.save(validate: false)
        end
      end
    end
  end

  desc "clear all top posts"
  task clear_all_top_posts: :environment do
    Post.update_all(top: 0)
  end

  desc "change primary key's type to object id"
  task change_to_object_id: :environment do
    class IdGenerator
      include Mongoid::Document
      def self.get_new_object_id
        g = self.create
        g.id
      end
    end

    relation_hash = {
        User => {
            Topic => {
                user_id: 0,
                locker_id: 0,
                unlocker_id: 0,
                deleter_id: 0,
                resumer_id: 0
            },
            Post => {
                author_id: 0,
                mentioned_user_ids: 1,
                deleter_id: 0,
                resumer_id: 0
            },
            Picture => {
                user_id: 0
            },
            Comment => {
                user_id: 0,
                mentioned_user_ids: 1,
                deleter_id: 0,
                resumer_id: 0
            },
            Board => {
                creator_id: 0,
                moderator_ids: 1
            },
            BlockedUser => {
                user_id: 0,
                blocker_id: 0
            },
            Notification::Base => {
                user_id: 0
            },
            Elite::Node => {
                moderator_id: 0,
                deleter_id: 0,
                resumer_id: 0
            },
            Elite::Post => {
                author_id: 0
            }
        },
        Topic => {
            Post => {
                topic_id: 0
            },
            Elite::Post => {
                topic_id: 0
            }
        },
        Post => {
            Comment => {
                commentable: 2
            },
            Post => {
                parent_id: 0
            },
            Notification::PostReply => {
                post_id: 0
            },
            Notification::Mention => {
                mentionable: 2
            },
            Elite::Post => {
                original_id: 0
            }
        },
        Picture => {
        },
        Node => {
            User => {
                managing_board_ids: 1,
                collecting_board_ids: 1
            },
            Topic => {
                board_id: 0
            },
            Post => {
                board_id: 0
            },
            Node => {
                parent_id: 0
            },
            Comment => {
                board_id: 0
            },
            BlockedUser => {
                blockable: 2
            },
            Elite::Node => {
                board_id: 0
            }
        },
        Comment => {
            Comment => {
                commentable: 2
            },
            Notification::Mention => {
                mentionable: 2
            },
            Notification::Comment => {
                comment_id: 0
            }
        },
        BlockedUser => {
        },
        Notification::Base => {
        },
        Elite::Node => {
            Elite::Node => {
                parent_id: 0
            }
        }
    }

    relation_hash.each do |klass, relations|
      p '#' + klass.to_s
{'fraction_non_alphanumeric': 0.09058592792351067, 'fraction_numerical': 0.010419220397156165, 'mean_word_length': 0.9683956574185766, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 74, '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': '2087048', 'n_tokens_mistral': 2379, 'n_tokens_neox': 2198, 'n_words': 490}