set/self/role.rb in card-mod-account-0.15.6 vs set/self/role.rb in card-mod-account-0.16.0

- old
+ new

@@ -1,20 +1,16 @@ class << self CACHE_KEY = "ROLEHASH".freeze - def load_rolehash - ::Card.cache.fetch(CACHE_KEY) do - generate_rolehash - end + def role_hash + @role_hash ||= load_rolehash end - def generate_rolehash - Auth.as_bot do - Card.search(left: { type_id: Card::RoleID }, right_id: Card::MembersID) - .each_with_object({}) do |member_card, hash| - hash[member_card.left_id] = ::Set.new member_card.item_ids - end + def role_ids user_id + role_hash.each_with_object([]) do |(role_id, member_ids), all_role_ids| + next unless member_ids.include? user_id + all_role_ids << role_id end end def update_rolehash role_id, member_ids role_hash[role_id] = member_ids @@ -23,16 +19,22 @@ def clear_rolehash @role_hash = nil end - def role_hash - @role_hash ||= load_rolehash + private + + def load_rolehash + ::Card.cache.fetch(CACHE_KEY) do + generate_rolehash + end end - def role_ids user_id - role_hash.each_with_object([]) do |(role_id, member_ids), all_role_ids| - next unless member_ids.include? user_id - all_role_ids << role_id + def generate_rolehash + Auth.as_bot do + Card.search(left: { type_id: Card::RoleID }, right_id: Card::MembersID) + .each_with_object({}) do |member_card, hash| + hash[member_card.left_id] = ::Set.new member_card.item_ids + end end end end