2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-07-28 08:14:06 +08:00
|
|
|
class Developer < ActiveRecord::Base
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
after_save :rebuild_cache
|
|
|
|
after_destroy :rebuild_cache
|
|
|
|
|
2023-08-18 23:59:11 +08:00
|
|
|
def self.id_cache
|
|
|
|
@id_cache ||= DistributedCache.new("developer_ids")
|
|
|
|
end
|
2016-07-28 08:14:06 +08:00
|
|
|
|
|
|
|
def self.user_ids
|
2023-08-18 23:59:11 +08:00
|
|
|
id_cache.defer_get_set("ids") { Set.new(Developer.pluck(:user_id)) }
|
2016-07-28 08:14:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.rebuild_cache
|
2023-08-18 23:59:11 +08:00
|
|
|
id_cache.clear
|
2016-07-28 08:14:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def rebuild_cache
|
|
|
|
Developer.rebuild_cache
|
|
|
|
end
|
|
|
|
end
|
2016-08-15 15:44:24 +08:00
|
|
|
|
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: developers
|
|
|
|
#
|
|
|
|
# id :integer not null, primary key
|
|
|
|
# user_id :integer not null
|
|
|
|
#
|
2019-11-29 23:49:08 +08:00
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# index_developers_on_user_id (user_id) UNIQUE
|
|
|
|
#
|