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: score_calculator.rb
    path of file: ./repos/discourse/lib
    
    the code of the file until where you have to start completion: # frozen_string_literal: true

class ScoreCalculator
  def self.default_score_weights
    { reply_count: 5, like_score: 15, incoming_link_count: 5, bookmark_count: 2, reads: 0.2 }
  end

  def initialize(weightings = nil)
    @weightings = weightings || ScoreCalculator.default_score_weights
  end

  # Calculate the score for all posts based on the weightings
  def calculate(opts = nil)
    update_posts_score(opts)
    update_posts_rank(opts)
    update_topics_rank(opts)
  end

  private

  def update_posts_score(opts)
    limit = 20_000

    components = []
    @weightings.each_key { |k| components << "COALESCE(posts.#{k}, 0)
    
  def update_posts_rank(opts)
    limit = 20_000

    builder = DB.build <<~SQL
      UPDATE posts
      SET percent_rank = X.percent_rank
      FROM (
        SELECT posts.id, Y.percent_rank
        FROM posts
        JOIN (
          SELECT id, percent_rank()
                       OVER (PARTITION BY topic_id ORDER BY SCORE DESC) as percent_rank
          FROM posts
         ) Y ON Y.id = posts.id
         JOIN topics ON posts.topic_id = topics.id
        /*where*/
        LIMIT #{limit}
      ) AS X
      WHERE posts.id = X.id
    SQL

    builder.where("posts.percent_rank IS NULL OR Y.percent_rank <> posts.percent_rank")

    filter_topics(builder, opts)

    while builder.exec == limit
    end