forked from Gitlink/forgeplus
Merge branch 'develop' into dev_trustie_server
This commit is contained in:
commit
632a06e575
|
@ -32,7 +32,7 @@ class Admins::AuthSchoolsController < Admins::BaseController
|
|||
def search_manager
|
||||
school = School.find_by(id: params[:school_id])
|
||||
user_ids = school&.ec_school_users&.pluck(:user_id)
|
||||
@users = User.where.not(id: user_ids).where("concat(lastname, firstname) like ?", "%#{params[:name].strip.to_s}%").limit(10)
|
||||
@users = User.where.not(id: user_ids).where("CONCAT_WS(lastname, firstname, nickname) like ?", "%#{params[:name].strip.to_s}%").limit(10)
|
||||
end
|
||||
|
||||
# 添加认证学校管理员
|
||||
|
|
|
@ -32,7 +32,7 @@ class Admins::LaboratoriesController < Admins::BaseController
|
|||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'shixuns.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword '\
|
||||
like_sql = 'shixuns.name LIKE :keyword OR CONCAT_WS(users.lastname, users.firstname, users.nickname) LIKE :keyword '\
|
||||
'OR mirror_repositories.name LIKE :keyword'
|
||||
shixuns = shixuns.joins(:user, :mirror_repositories).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
@ -48,7 +48,7 @@ class Admins::LaboratoriesController < Admins::BaseController
|
|||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword'
|
||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT_WS(users.lastname, users.firstname, users.nickname) LIKE :keyword'
|
||||
subjects = subjects.joins(:user).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ class MembersController < ApplicationController
|
|||
scope = @project.members.includes(:roles, user: :user_extension)
|
||||
search = params[:search].to_s.downcase
|
||||
role = params[:role].to_s
|
||||
scope = scope.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
||||
scope = scope.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
||||
scope = scope.joins(:roles).where("roles.name LIKE ?", "%#{role}%") if role.present?
|
||||
|
||||
@total_count = scope.size
|
||||
|
|
|
@ -5,7 +5,7 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
|
|||
def index
|
||||
@organization_users = @organization.organization_users.includes(:user)
|
||||
search = params[:search].to_s.downcase
|
||||
@organization_users = @organization_users.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
||||
@organization_users = @organization_users.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present?
|
||||
|
||||
@organization_users = kaminari_paginate(@organization_users)
|
||||
end
|
||||
|
|
|
@ -85,19 +85,19 @@ class Users::StatisticsController < Users::BaseController
|
|||
for key in @project_languages_count.keys do
|
||||
@languages_percent[key] = (@project_languages_count[key].to_f / @project_languages_count.values.sum).round(2)
|
||||
end
|
||||
@platform_languages_percent = Hash.new
|
||||
for key in @platform_project_languages_count.keys do
|
||||
@platform_languages_percent[key] = (@platform_project_languages_count[key].to_f / @platform_project_languages_count.values.sum).round(2)
|
||||
end
|
||||
# @platform_languages_percent = Hash.new
|
||||
# for key in @platform_project_languages_count.keys do
|
||||
# @platform_languages_percent[key] = (@platform_project_languages_count[key].to_f / @platform_project_languages_count.values.sum).round(2)
|
||||
# end
|
||||
# 各门语言分数
|
||||
@each_language_score = Hash.new
|
||||
for key in @project_languages_count.keys do
|
||||
@each_language_score[key] = (60.0 + @project_languages_count[key] / (@project_languages_count[key] + 5.0) * 40.0).to_i
|
||||
end
|
||||
@platform_each_language_score = Hash.new
|
||||
for key in @platform_project_languages_count.keys do
|
||||
@platform_each_language_score[key] = (60.0 + @platform_project_languages_count[key] / (@platform_project_languages_count[key] + 5.0) * 40.0).to_i
|
||||
end
|
||||
# @platform_each_language_score = Hash.new
|
||||
# for key in @platform_project_languages_count.keys do
|
||||
# @platform_each_language_score[key] = (60.0 + @platform_project_languages_count[key] / (@platform_project_languages_count[key] + 5.0) * 40.0).to_i
|
||||
# end
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -162,29 +162,56 @@ class Users::StatisticsController < Users::BaseController
|
|||
end
|
||||
|
||||
def preload_develop_data
|
||||
# 用户被follow数量
|
||||
@follow_count = time_filter(Watcher.where(watchable: observed_user), 'created_at').count
|
||||
@platform_follow_count = time_filter(Watcher.where(watchable_type: 'User'), 'created_at').count
|
||||
# 用户pr数量
|
||||
@pullrequest_count = time_filter(PullRequest.where(user_id: observed_user.id), 'created_at').count
|
||||
@platform_pullrequest_count = time_filter(PullRequest, 'created_at').count
|
||||
# 用户issue数量
|
||||
@issues_count = time_filter(Issue.where(author_id: observed_user.id), 'created_on').count
|
||||
@platform_issues_count = time_filter(Issue, 'created_on').count
|
||||
# 用户总项目数 @fork_count + @project_watchers_count + @project_praises_count
|
||||
@project_count = filter_member_projects_by_role("Owner").count
|
||||
@platform_project_count = time_filter(Project, 'created_on').count
|
||||
# 用户项目被fork数量
|
||||
@fork_count = filter_member_projects_by_role("Owner").sum("forked_count")
|
||||
@platform_fork_count = time_filter(Project, 'created_on').sum("forked_count")
|
||||
# 用户项目关注数
|
||||
@project_watchers_count = filter_member_projects_by_role("Owner").sum("watchers_count")
|
||||
@platform_project_watchers_count = time_filter(Project, 'created_on').sum("watchers_count")
|
||||
# 用户项目点赞数
|
||||
@project_praises_count = filter_member_projects_by_role("Owner").sum("praises_count")
|
||||
@platform_project_praises_count = time_filter(Project, 'created_on').sum("praises_count")
|
||||
# 用户不同语言项目数量
|
||||
@project_languages_count = filter_member_projects_by_role("Owner").joins(:project_language).group("project_languages.name").count
|
||||
@platform_project_languages_count = time_filter(Project, 'created_on').joins(:project_language).group("project_languages.name").count
|
||||
if params[:start_time].present? && params[:end_time].present?
|
||||
# 用户被follow数量
|
||||
@follow_count = time_filter(Watcher.where(watchable: observed_user), 'created_at').count
|
||||
@platform_follow_count = time_filter(Watcher.where(watchable_type: 'User'), 'created_at').count
|
||||
# 用户pr数量
|
||||
@pullrequest_count = time_filter(PullRequest.where(user_id: observed_user.id), 'created_at').count
|
||||
@platform_pullrequest_count = time_filter(PullRequest, 'created_at').count
|
||||
# 用户issue数量
|
||||
@issues_count = time_filter(Issue.where(author_id: observed_user.id), 'created_on').count
|
||||
@platform_issues_count = time_filter(Issue, 'created_on').count
|
||||
# 用户总项目数
|
||||
@project_count = time_filter(Project.where(user_id:observed_user.id), 'created_on').count
|
||||
@platform_project_count = time_filter(Project, 'created_on').count
|
||||
# 用户项目被fork数量
|
||||
@fork_count = time_filter(Project.where(user_id:observed_user.id), 'created_on').sum("forked_count")
|
||||
@platform_fork_count = time_filter(Project, 'created_on').sum("forked_count")
|
||||
# 用户项目关注数
|
||||
@project_watchers_count = time_filter(Project.where(user_id: observed_user.id), 'created_on').sum("watchers_count")
|
||||
@platform_project_watchers_count = time_filter(Project, 'created_on').sum("watchers_count")
|
||||
# 用户项目点赞数
|
||||
@project_praises_count = time_filter(Project.where(user_id: observed_user.id), 'created_on').sum("praises_count")
|
||||
@platform_project_praises_count = time_filter(Project, 'created_on').sum("praises_count")
|
||||
# 用户不同语言项目数量
|
||||
@project_languages_count = time_filter(Project.where(user_id: observed_user.id), 'created_on').joins(:project_language).group("project_languages.name").count
|
||||
@platform_project_languages_count = time_filter(Project, 'created_on').joins(:project_language).group("project_languages.name").count
|
||||
else
|
||||
# 用户被follow数量
|
||||
@follow_count = Cache::UserFollowCountService.call(observed_user)
|
||||
@platform_follow_count = Cache::PlatformFollowCountService.call
|
||||
# 用户pr数量
|
||||
@pullrequest_count = Cache::UserPullrequestCountService.call(observed_user)
|
||||
@platform_pullrequest_count = Cache::PlatformPullrequestCountService.call
|
||||
# 用户issue数量
|
||||
@issues_count = Cache::UserIssueCountService.call(observed_user)
|
||||
@platform_issues_count = Cache::PlatformIssueCountService.call
|
||||
# 用户总项目数
|
||||
@project_count = Cache::UserProjectCountService.call(observed_user)
|
||||
@platform_project_count = Cache::PlatformProjectCountService.call
|
||||
# 用户项目被fork数量
|
||||
@fork_count = Cache::UserProjectForkCountService.call(observed_user)
|
||||
@platform_fork_count = Cache::PlatformProjectForkCountService.call
|
||||
# 用户项目关注数
|
||||
@project_watchers_count = Cache::UserProjectWatchersCountService.call(observed_user)
|
||||
@platform_project_watchers_count = Cache::PlatformProjectWatchersCountService.call
|
||||
# 用户项目点赞数
|
||||
@project_praises_count = Cache::UserProjectPraisesCountService.call(observed_user)
|
||||
@platform_project_praises_count = Cache::PlatformProjectPraisesCountService.call
|
||||
# 用户不同语言项目数量
|
||||
@project_languages_count = Cache::UserProjectLanguagesCountService.call(observed_user)
|
||||
@platform_project_languages_count = Cache::PlatformProjectLanguagesCountService.call
|
||||
end
|
||||
end
|
||||
end
|
|
@ -63,7 +63,7 @@ class UsersController < ApplicationController
|
|||
|
||||
def fan_users
|
||||
watchers = @user.watchers.includes(:user).order("watchers.created_at desc")
|
||||
watchers = watchers.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login)) LIKE ?", "%#{params[:search].split(" ").join('|')}%") if params[:search].present?
|
||||
watchers = watchers.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.login, users.nickname)) LIKE ?", "%#{params[:search].split(" ").join('|')}%") if params[:search].present?
|
||||
|
||||
@watchers_count = watchers.size
|
||||
@watchers = paginate(watchers)
|
||||
|
|
|
@ -11,7 +11,7 @@ class UsersForPrivateMessagesController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
users = users.where('LOWER(concat(lastname, firstname, nickname)) LIKE ?', "%#{keyword}%")
|
||||
users = users.where('LOWER(CONCAT_WS(lastname, firstname, nickname)) LIKE ?', "%#{keyword}%")
|
||||
|
||||
@users = users.limit(10).includes(:user_extension)
|
||||
end
|
||||
|
|
|
@ -86,7 +86,7 @@ class Weapps::CoursesController < Weapps::BaseController
|
|||
end
|
||||
|
||||
if search.present?
|
||||
@teacher_list = @teacher_list.joins(:user).where("LOWER(CONCAT(users.lastname, users.firstname)) like ?", "%#{search}%")
|
||||
@teacher_list = @teacher_list.joins(:user).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.nickname)) like ?", "%#{search}%")
|
||||
end
|
||||
|
||||
@teacher_list_size = @teacher_list.size
|
||||
|
@ -127,7 +127,7 @@ class Weapps::CoursesController < Weapps::BaseController
|
|||
@students = CourseMember.students(@course)
|
||||
|
||||
if search.present?
|
||||
@students = @students.joins(user: :user_extension).where("LOWER(CONCAT(users.lastname, users.firstname)) like ? or
|
||||
@students = @students.joins(user: :user_extension).where("LOWER(CONCAT_WS(users.lastname, users.firstname, users.nickname)) like ? or
|
||||
user_extensions.student_id like ?", "%#{search}%", "%#{search}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -86,7 +86,7 @@ class ZipsController < ApplicationController
|
|||
|
||||
#搜索
|
||||
if params[:search].present?
|
||||
@ex_users = @ex_users.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
|
||||
@ex_users = @ex_users.joins(user: :user_extension).where("CONCAT_WS(lastname, firstname, nickname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
|
||||
end
|
||||
|
||||
default_ex_users_size = @ex_users&.size
|
||||
|
@ -130,7 +130,7 @@ class ZipsController < ApplicationController
|
|||
end
|
||||
|
||||
unless params[:search].blank?
|
||||
@all_student_works = @all_student_works.joins(user: :user_extension).where("concat(lastname, firstname) like ?
|
||||
@all_student_works = @all_student_works.joins(user: :user_extension).where("CONCAT_WS(lastname, firstname, nickname) like ?
|
||||
or student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
class ResetPlatformCacheJob < ApplicationJob
|
||||
queue_as :cache
|
||||
|
||||
def perform
|
||||
Cache::PlatformFollowCountService.new.reset
|
||||
Cache::PlatformIssueCountService.new.reset
|
||||
Cache::PlatformProjectCountService.new.reset
|
||||
Cache::PlatformProjectForkCountService.new.reset
|
||||
Cache::PlatformProjectLanguagesCountService.new.reset
|
||||
Cache::PlatformProjectPraisesCountService.new.reset
|
||||
Cache::PlatformProjectWatchersCountService.new.reset
|
||||
Cache::PlatformPullrequestCountService.new.reset
|
||||
end
|
||||
end
|
|
@ -0,0 +1,14 @@
|
|||
class ResetUserCacheJob < ApplicationJob
|
||||
queue_as :cache
|
||||
|
||||
def perform(user)
|
||||
Cache::UserFollowCountService.new(user).reset
|
||||
Cache::UserIssueCountService.new(user).reset
|
||||
Cache::UserProjectCountService.new(user).reset
|
||||
Cache::UserProjectForkCountService.new(user).reset
|
||||
Cache::UserProjectLanguagesCountService.new(user).reset
|
||||
Cache::UserProjectPraisesCountService.new(user).reset
|
||||
Cache::UserProjectWatchersCountService.new(user).reset
|
||||
Cache::UserPullrequestCountService.new(user).reset
|
||||
end
|
||||
end
|
|
@ -16,4 +16,12 @@ class ApplicationRecord < ActiveRecord::Base
|
|||
def allow_sync_to_trustie?
|
||||
Rails.env.production? && EduSetting.get('host_name') == 'https://www.educoder.net'
|
||||
end
|
||||
|
||||
def reset_user_cache_async_job(user)
|
||||
ResetUserCacheJob.perform_later(user)
|
||||
end
|
||||
|
||||
def reset_platform_cache_async_job
|
||||
ResetPlatformCacheJob.perform_later
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,42 +1,42 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: attachments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# container_id :integer
|
||||
# container_type :string(30)
|
||||
# filename :string(255) default(""), not null
|
||||
# disk_filename :string(255) default(""), not null
|
||||
# filesize :integer default("0"), not null
|
||||
# content_type :string(255) default("")
|
||||
# digest :string(60) default(""), not null
|
||||
# downloads :integer default("0"), not null
|
||||
# author_id :integer default("0"), not null
|
||||
# created_on :datetime
|
||||
# description :text(65535)
|
||||
# disk_directory :string(255)
|
||||
# attachtype :integer default("1")
|
||||
# is_public :integer default("1")
|
||||
# copy_from :integer
|
||||
# quotes :integer default("0")
|
||||
# is_publish :integer default("1")
|
||||
# publish_time :datetime
|
||||
# resource_bank_id :integer
|
||||
# unified_setting :boolean default("1")
|
||||
# cloud_url :string(255) default("")
|
||||
# course_second_category_id :integer default("0")
|
||||
# delay_publish :boolean default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_attachments_on_author_id (author_id)
|
||||
# index_attachments_on_container_id_and_container_type (container_id,container_type)
|
||||
# index_attachments_on_course_second_category_id (course_second_category_id)
|
||||
# index_attachments_on_created_on (created_on)
|
||||
# index_attachments_on_is_public (is_public)
|
||||
# index_attachments_on_quotes (quotes)
|
||||
#
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: attachments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# container_id :integer
|
||||
# container_type :string(30)
|
||||
# filename :string(255) default(""), not null
|
||||
# disk_filename :string(255) default(""), not null
|
||||
# filesize :integer default("0"), not null
|
||||
# content_type :string(255) default("")
|
||||
# digest :string(60) default(""), not null
|
||||
# downloads :integer default("0"), not null
|
||||
# author_id :integer default("0"), not null
|
||||
# created_on :datetime
|
||||
# description :text(65535)
|
||||
# disk_directory :string(255)
|
||||
# attachtype :integer default("1")
|
||||
# is_public :integer default("1")
|
||||
# copy_from :integer
|
||||
# quotes :integer default("0")
|
||||
# is_publish :integer default("1")
|
||||
# publish_time :datetime
|
||||
# resource_bank_id :integer
|
||||
# unified_setting :boolean default("1")
|
||||
# cloud_url :string(255) default("")
|
||||
# course_second_category_id :integer default("0")
|
||||
# delay_publish :boolean default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_attachments_on_author_id (author_id)
|
||||
# index_attachments_on_container_id_and_container_type (container_id,container_type)
|
||||
# index_attachments_on_course_second_category_id (course_second_category_id)
|
||||
# index_attachments_on_created_on (created_on)
|
||||
# index_attachments_on_is_public (is_public)
|
||||
# index_attachments_on_quotes (quotes)
|
||||
#
|
||||
|
||||
class Attachment < ApplicationRecord
|
||||
include BaseModel
|
||||
include Publicable
|
||||
|
@ -51,7 +51,7 @@ class Attachment < ApplicationRecord
|
|||
# 二级目录
|
||||
# belongs_to :course_second_category, optional: true
|
||||
|
||||
scope :by_filename_or_user_name, -> (keywords) { joins(:author).where("filename like :search or LOWER(concat(users.lastname, users.firstname)) LIKE :search",
|
||||
scope :by_filename_or_user_name, -> (keywords) { joins(:author).where("filename like :search or LOWER(CONCAT_WS(users.lastname, users.firstname, users.nickname)) LIKE :search",
|
||||
:search => "%#{keywords.split(" ").join('|')}%") unless keywords.blank? }
|
||||
scope :by_keywords, -> (keywords) { where("filename LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank? }
|
||||
scope :ordered, -> (opts = {}) { order("#{opts[:sort_type]} #{opts[:sort] == 1 ? 'asc': 'desc'}") }
|
||||
|
|
|
@ -20,4 +20,12 @@ class ForkUser < ApplicationRecord
|
|||
belongs_to :user
|
||||
belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id
|
||||
|
||||
after_save :reset_cache_data
|
||||
after_destroy :reset_cache_data
|
||||
|
||||
def reset_cache_data
|
||||
self.reset_platform_cache_async_job
|
||||
self.reset_user_cache_async_job(self.project.owner)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -76,8 +76,13 @@ class Issue < ApplicationRecord
|
|||
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
|
||||
|
||||
after_update :change_versions_count
|
||||
after_destroy :update_closed_issues_count_in_project!
|
||||
after_save :reset_cache_data
|
||||
after_destroy :update_closed_issues_count_in_project!, :reset_cache_data
|
||||
|
||||
def reset_cache_data
|
||||
self.reset_platform_cache_async_job
|
||||
self.reset_user_cache_async_job(self.user)
|
||||
end
|
||||
|
||||
def get_assign_user
|
||||
User&.find_by_id(self.assigned_to_id) if self.assigned_to_id.present?
|
||||
|
|
|
@ -1,26 +1,35 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: praise_treads
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer not null
|
||||
# praise_tread_object_id :integer
|
||||
# praise_tread_object_type :string(255)
|
||||
# praise_or_tread :integer default("1")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# praise_tread (praise_tread_object_id,praise_tread_object_type)
|
||||
#
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: praise_treads
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer not null
|
||||
# praise_tread_object_id :integer
|
||||
# praise_tread_object_type :string(255)
|
||||
# praise_or_tread :integer default("1")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# praise_tread (praise_tread_object_id,praise_tread_object_type)
|
||||
#
|
||||
|
||||
class PraiseTread < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :praise_tread_object, polymorphic: true, counter_cache: :praises_count
|
||||
has_many :tidings, :as => :container, :dependent => :destroy
|
||||
|
||||
after_create :send_tiding
|
||||
after_save :reset_cache_data
|
||||
after_destroy :reset_cache_data
|
||||
|
||||
def reset_cache_data
|
||||
self.reset_platform_cache_async_job
|
||||
if self.praise_tread_object.is_a?(Project)
|
||||
self.reset_user_cache_async_job(self.praise_tread_object&.owner)
|
||||
end
|
||||
end
|
||||
|
||||
def send_tiding
|
||||
case self.praise_tread_object_type
|
||||
|
|
|
@ -105,7 +105,8 @@ class Project < ApplicationRecord
|
|||
has_many :pinned_projects, dependent: :destroy
|
||||
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
||||
|
||||
after_save :check_project_members
|
||||
after_save :check_project_members, :reset_cache_data
|
||||
after_destroy :reset_cache_data
|
||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
|
||||
|
@ -113,6 +114,14 @@ class Project < ApplicationRecord
|
|||
delegate :content, to: :project_detail, allow_nil: true
|
||||
delegate :name, to: :license, prefix: true, allow_nil: true
|
||||
|
||||
def reset_cache_data
|
||||
if changes[:user_id].present?
|
||||
first_owner = Owner.find_by_id(changes[:user_id].first)
|
||||
self.reset_user_cache_async_job(first_owner)
|
||||
end
|
||||
self.reset_platform_cache_async_job
|
||||
self.reset_user_cache_async_job(self.owner)
|
||||
end
|
||||
|
||||
def self.search_project(search)
|
||||
ransack(name_or_identifier_cont: search)
|
||||
|
|
|
@ -33,6 +33,14 @@ class PullRequest < ApplicationRecord
|
|||
has_many :project_trends, as: :trend, dependent: :destroy
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
|
||||
after_save :reset_cache_data
|
||||
after_destroy :reset_cache_data
|
||||
|
||||
def reset_cache_data
|
||||
self.reset_platform_cache_async_job
|
||||
self.reset_user_cache_async_job(self.user)
|
||||
end
|
||||
|
||||
def fork_project
|
||||
Project.find_by(id: self.fork_project_id)
|
||||
end
|
||||
|
|
|
@ -171,7 +171,7 @@ class User < Owner
|
|||
# Groups and active users
|
||||
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
|
||||
scope :like, lambda { |keywords|
|
||||
sql = "CONCAT(lastname, firstname) LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search"
|
||||
sql = "CONCAT_WS(lastname, firstname, nickname) LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search"
|
||||
where(sql, :search => "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
||||
}
|
||||
|
||||
|
|
|
@ -15,10 +15,24 @@
|
|||
# watchers_user_id_type (user_id,watchable_type)
|
||||
#
|
||||
|
||||
class Watcher < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
belongs_to :watchable, polymorphic: true, counter_cache: :watchers_count
|
||||
|
||||
scope :watching_users, ->(watchable_id){ where("watchable_type = ? and user_id = ?",'User',watchable_id)}
|
||||
end
|
||||
class Watcher < ApplicationRecord
|
||||
belongs_to :user
|
||||
|
||||
belongs_to :watchable, polymorphic: true, counter_cache: :watchers_count
|
||||
|
||||
scope :watching_users, ->(watchable_id){ where("watchable_type = ? and user_id = ?",'User',watchable_id)}
|
||||
|
||||
after_save :reset_cache_data
|
||||
after_destroy :reset_cache_data
|
||||
|
||||
def reset_cache_data
|
||||
if self.watchable.is_a?(User)
|
||||
self.reset_user_cache_async_job(self.watchable)
|
||||
end
|
||||
if self.watchable.is_a?(Project)
|
||||
self.reset_user_cache_async_job(self.watchable&.owner)
|
||||
end
|
||||
self.reset_platform_cache_async_job
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ class Admins::ApplyItemBankQuery < ApplicationQuery
|
|||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
applies = applies.joins(user: { user_extension: :school })
|
||||
.where('CONCAT(lastname,firstname) LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%")
|
||||
.where('CONCAT_WS(lastname,firstname, nickname) LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
custom_sort(applies, params[:sort_by], params[:sort_direction])
|
||||
|
|
|
@ -26,7 +26,7 @@ class Admins::ApplyUserAuthenticationQuery < ApplicationQuery
|
|||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
applies = applies.joins(user: { user_extension: :school })
|
||||
.where('CONCAT(lastname,firstname) LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%")
|
||||
.where('CONCAT_WS(lastname,firstname,nickname) LIKE :keyword OR schools.name LIKE :keyword', keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
custom_sort(applies, params[:sort_by], params[:sort_direction])
|
||||
|
|
|
@ -19,7 +19,7 @@ class Admins::CourseListQuery < ApplicationQuery
|
|||
case search_type
|
||||
when "0"
|
||||
course_lists = course_lists.joins(:user)
|
||||
.where('CONCAT(lastname, firstname) like :keyword', keyword: "%#{keyword}%")
|
||||
.where('CONCAT_WS(lastname, firstname, nickname) like :keyword', keyword: "%#{keyword}%")
|
||||
when "1"
|
||||
course_lists = course_lists.where('name like :keyword', keyword: "%#{keyword}%")
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ class Admins::CourseQuery < ApplicationQuery
|
|||
# 关键字
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword
|
||||
sql = 'CONCAT(lastname, firstname) LIKE :keyword OR courses.name LIKE :keyword OR course_lists.name LIKE :keyword'
|
||||
sql = 'CONCAT_WS(lastname, firstname, nickname) LIKE :keyword OR courses.name LIKE :keyword OR course_lists.name LIKE :keyword'
|
||||
courses = courses.joins(:teacher, :course_list).where(sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class Admins::LaboratoryShixunQuery < ApplicationQuery
|
|||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'shixuns.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword'
|
||||
like_sql = 'shixuns.name LIKE :keyword OR CONCAT_WS(users.lastname, users.firstname, users.nickname) LIKE :keyword'
|
||||
laboratory_shixuns = laboratory_shixuns.joins(shixun: :user).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ class Admins::LaboratorySubjectQuery < ApplicationQuery
|
|||
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword.present?
|
||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT(users.lastname, users.firstname) LIKE :keyword'
|
||||
like_sql = 'subjects.name LIKE :keyword OR CONCAT_WS(users.lastname, users.firstname, users.nickname) LIKE :keyword'
|
||||
laboratory_subjects = laboratory_subjects.joins(subject: :user).where(like_sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ class Admins::SubjectQuery < ApplicationQuery
|
|||
# 关键字
|
||||
keyword = params[:keyword].to_s.strip
|
||||
if keyword
|
||||
sql = 'CONCAT(lastname, firstname) LIKE :keyword OR subjects.name LIKE :keyword'
|
||||
sql = 'CONCAT_WS(lastname, firstname, nickname) LIKE :keyword OR subjects.name LIKE :keyword'
|
||||
subjects = subjects.joins(:user).where(sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
|
|
|
@ -30,14 +30,14 @@ class Admins::UserQuery < ApplicationQuery
|
|||
# 关键字检索
|
||||
keyword = params[:keyword].to_s.strip.presence
|
||||
if keyword
|
||||
sql = 'CONCAT(lastname, firstname) LIKE :keyword OR login LIKE :keyword OR mail LIKE :keyword OR phone LIKE :keyword'
|
||||
sql = 'CONCAT_WS(lastname, firstname, nickname) LIKE :keyword OR login LIKE :keyword OR mail LIKE :keyword OR phone LIKE :keyword'
|
||||
users = users.where(sql, keyword: "%#{keyword}%")
|
||||
end
|
||||
|
||||
# 姓名
|
||||
name = params[:name].to_s.strip.presence
|
||||
if name.present?
|
||||
users = users.where('CONCAT(lastname, firstname) LIKE :name', name: "%#{name}%")
|
||||
users = users.where('CONCAT_WS(lastname, firstname, nickname) LIKE :name', name: "%#{name}%")
|
||||
end
|
||||
|
||||
# 单位ID
|
||||
|
|
|
@ -10,7 +10,7 @@ class UserQuery < ApplicationQuery
|
|||
|
||||
# 真实姓名
|
||||
if name = strip_param(:name)
|
||||
users = users.where('LOWER(CONCAT(users.lastname, users.firstname)) LIKE ?', "%#{name.downcase}%")
|
||||
users = users.where('LOWER(CONCAT_WS(users.lastname, users.firstname, users.nickname)) LIKE ?', "%#{name.downcase}%")
|
||||
end
|
||||
|
||||
# 单位名称
|
||||
|
|
|
@ -84,7 +84,7 @@ class Admins::ImportUserService < ApplicationService
|
|||
if data.identity.to_i == 1
|
||||
users = users.where(user_extensions: { student_id: data.student_id })
|
||||
else
|
||||
users = users.where(user_extensions: { technical_title: data.technical_title }).where('CONCAT(users.lastname,users.firstname) = ?', data.name)
|
||||
users = users.where(user_extensions: { technical_title: data.technical_title }).where('CONCAT_WS(users.lastname,users.firstname,users.nickname) = ?', data.name)
|
||||
end
|
||||
|
||||
users.first
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformFollowCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_follow_count
|
||||
|
||||
platform_follow_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_follow_count
|
||||
|
||||
platform_follow_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_follow_count_key
|
||||
"platform-follow-count"
|
||||
end
|
||||
|
||||
def platform_follow_count
|
||||
$redis_cache.get(platform_follow_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_follow_count
|
||||
if $redis_cache.exists(platform_follow_count_key)
|
||||
$redis_cache.incrby(platform_follow_count_key, increment_count)
|
||||
else
|
||||
reset_platform_follow_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_follow_count
|
||||
$redis_cache.set(platform_follow_count_key, Watcher.where(watchable_type: 'User').count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformIssueCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_issue_count
|
||||
|
||||
platform_issue_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_issue_count
|
||||
|
||||
platform_issue_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_issue_count_key
|
||||
"platform-issue-count"
|
||||
end
|
||||
|
||||
def platform_issue_count
|
||||
$redis_cache.get(platform_issue_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_issue_count
|
||||
if $redis_cache.exists(platform_issue_count_key)
|
||||
$redis_cache.incrby(platform_issue_count_key, increment_count)
|
||||
else
|
||||
reset_platform_issue_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_issue_count
|
||||
$redis_cache.set(platform_issue_count_key, Issue.count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformProjectCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_project_count
|
||||
|
||||
platform_project_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_project_count
|
||||
|
||||
platform_project_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_project_count_key
|
||||
"platform-project-count"
|
||||
end
|
||||
|
||||
def platform_project_count
|
||||
$redis_cache.get(platform_project_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_project_count
|
||||
if $redis_cache.exists(platform_project_count_key)
|
||||
$redis_cache.incrby(platform_project_count_key, increment_count)
|
||||
else
|
||||
reset_platform_project_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_project_count
|
||||
$redis_cache.set(platform_project_count_key, Project.count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformProjectForkCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_project_fork_count
|
||||
|
||||
platform_project_fork_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_project_fork_count
|
||||
|
||||
platform_project_fork_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_project_fork_count_key
|
||||
"platform-project-fork-count"
|
||||
end
|
||||
|
||||
def platform_project_fork_count
|
||||
$redis_cache.get(platform_project_fork_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_project_fork_count
|
||||
if $redis_cache.exists(platform_project_fork_count_key)
|
||||
$redis_cache.incrby(platform_project_fork_count_key, increment_count)
|
||||
else
|
||||
reset_platform_project_fork_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_project_fork_count
|
||||
$redis_cache.set(platform_project_fork_count_key, ForkUser.count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class Cache::PlatformProjectLanguagesCountService < ApplicationService
|
||||
attr_reader :key, :increment_count
|
||||
|
||||
def initialize(key=nil, increment_count=0)
|
||||
@key = key
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_project_language_count
|
||||
|
||||
platform_project_language_count
|
||||
end
|
||||
|
||||
def reset_by_key
|
||||
reset_platform_project_language_count_by_key
|
||||
|
||||
platform_project_language_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_project_language_count
|
||||
|
||||
platform_project_language_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_project_language_count_key
|
||||
"platform-project-language-count"
|
||||
end
|
||||
|
||||
def platform_project_language_count
|
||||
$redis_cache.hgetall(platform_project_language_count_key).transform_values(&:to_i)
|
||||
end
|
||||
|
||||
def set_platform_project_language_count
|
||||
if $redis_cache.hlen(platform_project_language_count_key) == 0
|
||||
reset_platform_project_language_count
|
||||
elsif $redis_cache.hget(platform_project_language_count_key, key).nil?
|
||||
reset_platform_project_language_count_by_key
|
||||
else
|
||||
$redis_cache.hincrby(platform_project_language_count_key, key, increment_count)
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_project_language_count_by_key
|
||||
return if key.nil?
|
||||
$redis_cache.hset(platform_project_language_count_key, key, Project.joins(:project_language).where(project_languages: {name: key}).count)
|
||||
end
|
||||
|
||||
def reset_platform_project_language_count
|
||||
Project.joins(:project_language).group("project_languages.name").count.each do |k, v|
|
||||
$redis_cache.hset(platform_project_language_count_key, k, v)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformProjectPraisesCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_project_praises_count
|
||||
|
||||
platform_project_praises_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_project_praises_count
|
||||
|
||||
platform_project_praises_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_project_praises_count_key
|
||||
"platform-project-praises-count"
|
||||
end
|
||||
|
||||
def platform_project_praises_count
|
||||
$redis_cache.get(platform_project_praises_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_project_praises_count
|
||||
if $redis_cache.exists(platform_project_praises_count_key)
|
||||
$redis_cache.incrby(platform_project_praises_count_key, increment_count)
|
||||
else
|
||||
reset_platform_project_praises_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_project_praises_count
|
||||
$redis_cache.set(platform_project_praises_count_key, PraiseTread.where(praise_tread_object_type: "Project").count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformProjectWatchersCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_project_watchers_count
|
||||
|
||||
platform_project_watchers_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_project_watchers_count
|
||||
|
||||
platform_project_watchers_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_project_watchers_count_key
|
||||
"platform-project-watchers-count"
|
||||
end
|
||||
|
||||
def platform_project_watchers_count
|
||||
$redis_cache.get(platform_project_watchers_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_project_watchers_count
|
||||
if $redis_cache.exists(platform_project_watchers_count_key)
|
||||
$redis_cache.incrby(platform_project_watchers_count_key, increment_count)
|
||||
else
|
||||
reset_platform_project_watchers_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_project_watchers_count
|
||||
$redis_cache.set(platform_project_watchers_count_key, Watcher.where(watchable_type: 'Project').count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,41 @@
|
|||
class Cache::PlatformPullrequestCountService < ApplicationService
|
||||
attr_reader :increment_count
|
||||
|
||||
def initialize(increment_count=0)
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_platform_pullrequest_count
|
||||
|
||||
platform_pullrequest_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_platform_pullrequest_count
|
||||
|
||||
platform_pullrequest_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def platform_pullrequest_count_key
|
||||
"platform-pullrequest-count"
|
||||
end
|
||||
|
||||
def platform_pullrequest_count
|
||||
$redis_cache.get(platform_pullrequest_count_key).to_i
|
||||
end
|
||||
|
||||
def set_platform_pullrequest_count
|
||||
if $redis_cache.exists(platform_pullrequest_count_key)
|
||||
$redis_cache.incrby(platform_pullrequest_count_key, increment_count)
|
||||
else
|
||||
reset_platform_pullrequest_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_platform_pullrequest_count
|
||||
$redis_cache.set(platform_pullrequest_count_key, PullRequest.count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserFollowCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_follow_count
|
||||
|
||||
user_follow_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_follow_count
|
||||
|
||||
user_follow_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_follow_count_key
|
||||
"user-follow-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_follow_count
|
||||
$redis_cache.get(user_follow_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_follow_count
|
||||
if $redis_cache.exists(user_follow_count_key)
|
||||
$redis_cache.incrby(user_follow_count_key, increment_count)
|
||||
else
|
||||
reset_user_follow_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_follow_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_follow_count_key, Watcher.where(watchable: user).count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserIssueCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_issue_count
|
||||
|
||||
user_issue_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_issue_count
|
||||
|
||||
user_issue_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_issue_count_key
|
||||
"user-issue-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_issue_count
|
||||
$redis_cache.get(user_issue_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_issue_count
|
||||
if $redis_cache.exists(user_issue_count_key)
|
||||
$redis_cache.incrby(user_issue_count_key, increment_count)
|
||||
else
|
||||
reset_user_issue_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_issue_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_issue_count_key, Issue.where(author_id: user.id).count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserProjectCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_project_count
|
||||
|
||||
user_project_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_project_count
|
||||
|
||||
user_project_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_project_count_key
|
||||
"user-project-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_project_count
|
||||
$redis_cache.get(user_project_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_project_count
|
||||
if $redis_cache.exists(user_project_count_key)
|
||||
$redis_cache.incrby(user_project_count_key, increment_count)
|
||||
else
|
||||
reset_user_project_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_project_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_project_count_key, user.projects.count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserProjectForkCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_project_fork_count
|
||||
|
||||
user_project_fork_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_project_fork_count
|
||||
|
||||
user_project_fork_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_project_fork_count_key
|
||||
"user-project-fork-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_project_fork_count
|
||||
$redis_cache.get(user_project_fork_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_project_fork_count
|
||||
if $redis_cache.exists(user_project_fork_count_key)
|
||||
$redis_cache.incrby(user_project_fork_count_key, increment_count)
|
||||
else
|
||||
reset_user_project_fork_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_project_fork_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_project_fork_count_key, ForkUser.joins(:project).where(projects: {user_id: user.id}).count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,60 @@
|
|||
class Cache::UserProjectLanguagesCountService < ApplicationService
|
||||
attr_reader :user, :key, :increment_count
|
||||
|
||||
def initialize(user, key=nil, increment_count=0)
|
||||
@user = user
|
||||
@key = key
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_project_language_count
|
||||
|
||||
user_project_language_count
|
||||
end
|
||||
|
||||
def reset_by_key
|
||||
reset_user_project_language_count_by_key
|
||||
|
||||
user_project_language_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_project_language_count
|
||||
|
||||
user_project_language_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_project_language_count_key
|
||||
"user-project-language-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_project_language_count
|
||||
$redis_cache.hgetall(user_project_language_count_key).transform_values(&:to_i)
|
||||
end
|
||||
|
||||
def set_user_project_language_count
|
||||
if $redis_cache.hlen(user_project_language_count_key) == 0
|
||||
reset_user_project_language_count
|
||||
elsif $redis_cache.hget(user_project_language_count_key, key).nil?
|
||||
reset_user_project_language_count_by_key
|
||||
else
|
||||
$redis_cache.hincrby(user_project_language_count_key, key, increment_count)
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_project_language_count_by_key
|
||||
return if user.nil?
|
||||
return if key.nil?
|
||||
$redis_cache.hset(user_project_language_count_key, key, user.projects.joins(:project_language).where(project_languages: {name: key}).count)
|
||||
end
|
||||
|
||||
def reset_user_project_language_count
|
||||
return if user.nil?
|
||||
user.projects.joins(:project_language).group("project_languages.name").count.each do |k, v|
|
||||
$redis_cache.hset(user_project_language_count_key, k, v)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserProjectPraisesCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_project_praises_count
|
||||
|
||||
user_project_praises_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_project_praises_count
|
||||
|
||||
user_project_praises_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_project_praises_count_key
|
||||
"user-project-praises-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_project_praises_count
|
||||
$redis_cache.get(user_project_praises_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_project_praises_count
|
||||
if $redis_cache.exists(user_project_praises_count_key)
|
||||
$redis_cache.incrby(user_project_praises_count_key, increment_count)
|
||||
else
|
||||
reset_user_project_praises_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_project_praises_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_project_praises_count_key, PraiseTread.where(praise_tread_object_type: 'Project', praise_tread_object_id: user.projects).count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserProjectWatchersCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_project_watchers_count
|
||||
|
||||
user_project_watchers_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_project_watchers_count
|
||||
|
||||
user_project_watchers_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_project_watchers_count_key
|
||||
"user-project-watchers-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_project_watchers_count
|
||||
$redis_cache.get(user_project_watchers_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_project_watchers_count
|
||||
if $redis_cache.exists(user_project_watchers_count_key)
|
||||
$redis_cache.incrby(user_project_watchers_count_key, increment_count)
|
||||
else
|
||||
reset_user_project_watchers_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_project_watchers_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_project_watchers_count_key, Watcher.where(watchable_type: 'Project', watchable_id: user.projects).count)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,43 @@
|
|||
class Cache::UserPullrequestCountService < ApplicationService
|
||||
attr_reader :user, :increment_count
|
||||
|
||||
def initialize(user, increment_count=0)
|
||||
@user = user
|
||||
@increment_count = increment_count
|
||||
end
|
||||
|
||||
def call
|
||||
set_user_pullrequest_count
|
||||
|
||||
user_pullrequest_count
|
||||
end
|
||||
|
||||
def reset
|
||||
reset_user_pullrequest_count
|
||||
|
||||
user_pullrequest_count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def user_pullrequest_count_key
|
||||
"user-pullrequest-count-#{user.id}"
|
||||
end
|
||||
|
||||
def user_pullrequest_count
|
||||
$redis_cache.get(user_pullrequest_count_key).to_i
|
||||
end
|
||||
|
||||
def set_user_pullrequest_count
|
||||
if $redis_cache.exists(user_pullrequest_count_key)
|
||||
$redis_cache.incrby(user_pullrequest_count_key, increment_count)
|
||||
else
|
||||
reset_user_pullrequest_count
|
||||
end
|
||||
end
|
||||
|
||||
def reset_user_pullrequest_count
|
||||
return if user.nil?
|
||||
$redis_cache.set(user_pullrequest_count_key, PullRequest.where(user_id: user.id).count)
|
||||
end
|
||||
end
|
|
@ -4,8 +4,8 @@ json.platform do
|
|||
json.activity @platform_activity
|
||||
json.experience @platform_experience
|
||||
json.language @platform_language
|
||||
json.languages_percent @platform_languages_percent
|
||||
json.each_language_score @platform_each_language_score
|
||||
# json.languages_percent @platform_languages_percent
|
||||
# json.each_language_score @platform_each_language_score
|
||||
end
|
||||
|
||||
json.user do
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
redis_config = Rails.application.config_for(:redis)
|
||||
cache_url = redis_config["url"] || 'redis://localhost:6379'
|
||||
$redis_cache = Redis.new(url: cache_url, db: 2)
|
|
@ -7,3 +7,4 @@
|
|||
- [searchkick, 10]
|
||||
- [notify, 100]
|
||||
- [mailers, 101]
|
||||
- [cache, 10]
|
||||
|
|
Loading…
Reference in New Issue