Redis connection pooling updates

This commit is contained in:
Fosco Marotto 2021-01-16 13:52:11 -05:00
parent 8a3ed8d921
commit 8d48c3ce3d
6 changed files with 64 additions and 48 deletions

View File

@ -8,9 +8,11 @@ module Admin
@statuses_count = "." #Status.count @statuses_count = "." #Status.count
@pro_accounts_count = Account.where(is_pro: true).count @pro_accounts_count = Account.where(is_pro: true).count
@donor_accounts_count = Account.where(is_donor: true).count @donor_accounts_count = Account.where(is_donor: true).count
@registrations_week = Redis.current.get("activity:accounts:local:#{current_week}") || 0 Redis.current.with do |conn|
@logins_week = Redis.current.pfcount("activity:logins:#{current_week}") @registrations_week = conn.get("activity:accounts:local:#{current_week}") || 0
@interactions_week = Redis.current.get("activity:interactions:#{current_week}") || 0 @logins_week = conn.pfcount("activity:logins:#{current_week}")
@interactions_week = conn.get("activity:interactions:#{current_week}") || 0
end
@single_user_mode = Rails.configuration.x.single_user_mode @single_user_mode = Rails.configuration.x.single_user_mode
@search_enabled = Chewy.enabled? @search_enabled = Chewy.enabled?
@version = GabSocial::Version.to_s @version = GabSocial::Version.to_s
@ -35,7 +37,9 @@ module Admin
end end
def redis_info def redis_info
@redis_info ||= Redis.current.info Redis.current.with do |conn|
@redis_info ||= conn.info
end
end end
end end
end end

View File

@ -1,10 +1,14 @@
class Admin::TrendingHashtagsController < Admin::BaseController class Admin::TrendingHashtagsController < Admin::BaseController
def index def index
@trending_hashtags = Redis.current.get("admin_trending_hashtags") || '' Redis.current.with do |conn|
@trending_hashtags = conn.get("admin_trending_hashtags") || ''
end
end end
def create def create
Redis.current.set("admin_trending_hashtags", params[:trending_hashtags]) Redis.current.with do |conn|
conn.set("admin_trending_hashtags", params[:trending_hashtags])
end
redirect_to admin_trending_hashtags_path redirect_to admin_trending_hashtags_path
end end
end end

View File

@ -22,7 +22,8 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
@account = current_account @account = current_account
if !@account.user.confirmed? if !@account.user.confirmed?
redisResult = Redis.current.get("account:#{@account.id}:last_email_confirmation_resend") || 0 Redis.current.with do |conn|
redisResult = conn.get("account:#{@account.id}:last_email_confirmation_resend") || 0
@lastSentDate = redisResult @lastSentDate = redisResult
if redisResult != 0 if redisResult != 0
@ -31,10 +32,11 @@ class Api::V1::Accounts::CredentialsController < Api::BaseController
if @lastSentDate == 0 || (@lastSentDate != 0 && Time.now.utc - @lastSentDate >= 1.hour) if @lastSentDate == 0 || (@lastSentDate != 0 && Time.now.utc - @lastSentDate >= 1.hour)
@user = Account.find(@account.id).user || raise(ActiveRecord::RecordNotFound) @user = Account.find(@account.id).user || raise(ActiveRecord::RecordNotFound)
Redis.current.set("account:#{@account.id}:last_email_confirmation_resend", Time.now.utc.to_i) conn.set("account:#{@account.id}:last_email_confirmation_resend", Time.now.utc.to_i)
@user.resend_confirmation_instructions @user.resend_confirmation_instructions
end end
end end
end
render json: { success: true, message: 'ok' } render json: { success: true, message: 'ok' }
end end

View File

@ -3,7 +3,9 @@
class Api::V1::ExpensesController < EmptyController class Api::V1::ExpensesController < EmptyController
def show def show
amount = Redis.current.get("monthly_funding_amount") || 0 Redis.current.with do |conn|
amount = conn.get("monthly_funding_amount") || 0
end
amount = [amount.to_f, 100].min amount = [amount.to_f, 100].min
render json: { "expenses": amount } render json: { "expenses": amount }
end end

View File

@ -28,7 +28,8 @@ class Api::V1::PopularLinksController < Api::BaseController
end end
def get_cards def get_cards
body = Redis.current.get("popular_links:card_ids") Redis.current.with do |conn|
body = conn.get("popular_links:card_ids")
if body.nil? || body.empty? if body.nil? || body.empty?
statusIds = Status.where('statuses.created_at > ?', 24.hours.ago) statusIds = Status.where('statuses.created_at > ?', 24.hours.ago)
@ -51,8 +52,8 @@ class Api::V1::PopularLinksController < Api::BaseController
card_ids = cards.map(&:id) card_ids = cards.map(&:id)
Redis.current.set("popular_links:card_ids", card_ids.join(',')) conn.set("popular_links:card_ids", card_ids.join(','))
Redis.current.expire("popular_links:card_ids", 15.minutes.seconds) conn.expire("popular_links:card_ids", 15.minutes.seconds)
return cards return cards
else else
@ -61,5 +62,6 @@ class Api::V1::PopularLinksController < Api::BaseController
end end
end end
end
end end

View File

@ -3,7 +3,9 @@
class Api::V1::TrendingHashtagsController < EmptyController class Api::V1::TrendingHashtagsController < EmptyController
def show def show
tags = Redis.current.get("admin_trending_hashtags") || "" Redis.current.with do |conn|
tags = conn.get("admin_trending_hashtags") || ""
end
tags = tags.strip.split(", ") tags = tags.strip.split(", ")
render json: { trending_hashtags: tags } render json: { trending_hashtags: tags }
end end