You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: tag_methods.rb
    path of file: ./repos/moebooru/app/models/post
    
    the code of the file until where you have to start completion: module Post::TagMethods
  attr_accessor :tags, :new_tags, :old_tags, :old_cached_tags

  module ClassMethods
    def find_by_tags(tags, options = {})
      find_by_sql(Post.generate_sql(tags, options))
    end

    def recalculate_cached_tags(id = nil)
      conds = []
      cond_params = []

      sql = %{
        UPDATE posts p SET cached_tags = (
          SELECT array_to_string(coalesce(array(
            SELECT t.name

    
  def commit_metatags
    return if new_tags.nil?

    transaction do
      metatags, self.new_tags = new_tags.partition { |x| x =~ /^(hold|unhold|show|hide|\+flag|source:.*)$/ }
      metatags.each do |metatag|
        case metatag
        when /^hold$/
          self.is_held = true

        when /^unhold$/
          self.is_held = false

        when /^show$/
          self.is_shown_in_index = true

        when /^hide$/
          self.is_shown_in_index = false

        when /^\+flag$/
          # Permissions for this are checked on commit.
          self.metatag_flagged = "moderator flagged"
        when /^source:(.*)/
          self.source = Regexp.last_match[1]
        end
      end
    end