mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-24 13:45:44 +08:00
新增:活跃度计算访问量限制
This commit is contained in:
@@ -47,8 +47,13 @@ class RepositoriesController < ApplicationController
|
||||
end
|
||||
|
||||
def entries
|
||||
@project.increment!(:visits)
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
|
||||
@week_project_visit_record, @month_project_visit_record = TimeableVisitRecord.build(@project.id)
|
||||
if @week_project_visit_record.visits < 300 && @month_project_visit_record.visits < 1000
|
||||
@week_project_visit_record.increment!(:visits)
|
||||
@month_project_visit_record.increment!(:visits)
|
||||
@project.increment!(:visits)
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {visits: 1}, @project.id)
|
||||
end
|
||||
if @project.educoder?
|
||||
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
||||
else
|
||||
|
||||
28
app/models/timeable_visit_record.rb
Normal file
28
app/models/timeable_visit_record.rb
Normal file
@@ -0,0 +1,28 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: timeable_visit_records
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# time :string(255)
|
||||
# project_id :integer
|
||||
# visits :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_timeable_visit_records_on_project_id (project_id)
|
||||
# index_timeable_visit_records_on_time (time)
|
||||
#
|
||||
|
||||
class TimeableVisitRecord < ApplicationRecord
|
||||
|
||||
belongs_to :project
|
||||
|
||||
def self.build(project_id)
|
||||
week = TimeableVisitRecord.find_or_create_by!(time: Date.today.cweek, project_id: project_id)
|
||||
month = TimeableVisitRecord.find_or_create_by!(time: Date.today.strftime("%Y%m"), project_id: project_id)
|
||||
|
||||
return week, month
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user