• Igor Drozdov's avatar
    Reduce SQL requests number for CreateCommitSignatureWorker · 08cf5f7f
    Igor Drozdov authored
    Currently, the signatures are calculated as
    
    ```
    commits = commits.map do |commit|
      case commit.signature_type
        when :PGP
          Gitlab::Gpg::Commit.new(commit).signature
        when :X509
          Gitlab::X509::Commit.new(commit).signature
      end
    end
    ```
    
    In this case, the `lazy_signature&.itself` is directly called
    for every commit, but at that point, `BatchLoader` doesn't the
    information about a single commit and performs the query on every call.
    
    If we split the code into two steps: initialization and invocation:
    
    ```
    commits = commits.map do |commit|
      case commit.signature_type
        when :PGP
          Gitlab::Gpg::Commit.new(commit)
        when :X509
          Gitlab::X509::Commit.new(commit)
      end
    end
    ```
    
    will call `lazy_signature` for every commit, i.e store the information
    for a single one so on the invocation step:
    
    ```
    commits.each { |commit| commit.signature }
    ```
    
    `lazy_signature&.itself` will perform a single batch query since
    it already has the info about a single commit
    08cf5f7f
signed_commit.rb 769 Bytes