2020-08-08 19:08:48 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class FetchGroupsService < BaseService
|
|
|
|
def call(type)
|
|
|
|
|
|
|
|
if type == "featured"
|
2021-01-16 18:50:11 +00:00
|
|
|
body = Redis.current.with do |conn|
|
|
|
|
conn.get("groups:featuredgroups")
|
|
|
|
end
|
2020-08-08 19:08:48 +01:00
|
|
|
|
|
|
|
if body.nil? || !body || body.empty?
|
2021-02-10 17:43:23 +00:00
|
|
|
@groupIds = Group.where(is_featured: true, is_archived: false, is_private: false, is_visible: true).limit(150).all.pluck(:id)
|
2020-08-08 19:08:48 +01:00
|
|
|
|
2021-01-16 18:50:11 +00:00
|
|
|
Redis.current.with do |conn|
|
|
|
|
conn.set("groups:featuredgroups", @groupIds.join(","))
|
|
|
|
end
|
|
|
|
Redis.current.with do |conn|
|
|
|
|
conn.expire("groups:featuredgroups", 6.hours.seconds)
|
|
|
|
end
|
2020-08-08 19:08:48 +01:00
|
|
|
|
|
|
|
@groupIds
|
|
|
|
else
|
|
|
|
body.split(",")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|