summaryrefslogtreecommitdiff
path: root/app/models/lfs_objects_project.rb
blob: 674294f091608a0e9bffc978d56aebb3ebaa5710 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

class LfsObjectsProject < ApplicationRecord
  include ::EachBatch

  belongs_to :project
  belongs_to :lfs_object

  validates :lfs_object_id, presence: true
  validates :lfs_object_id, uniqueness: { scope: [:project_id, :repository_type], message: "already exists in repository" }
  validates :project_id, presence: true

  after_commit :update_project_statistics, on: [:create, :destroy]

  enum repository_type: {
    project: 0,
    wiki: 1,
    design: 2
  }

  scope :project_id_in, ->(ids) { where(project_id: ids) }

  private

  def update_project_statistics
    ProjectCacheWorker.perform_async(project_id, [], [:lfs_objects_size])
  end
end