Replace Makara with an initial Rails 6 role based splitting method.
This commit is contained in:
committed by
admin
parent
31922ea58b
commit
473c48b2aa
@@ -3,6 +3,7 @@
|
||||
#
|
||||
# Table name: accounts
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# username :string default(""), not null
|
||||
# domain :string
|
||||
# secret :string default(""), not null
|
||||
@@ -19,11 +20,11 @@
|
||||
# url :string
|
||||
# avatar_file_name :string
|
||||
# avatar_content_type :string
|
||||
# avatar_file_size :bigint(8)
|
||||
# avatar_file_size :integer
|
||||
# avatar_updated_at :datetime
|
||||
# header_file_name :string
|
||||
# header_content_type :string
|
||||
# header_file_size :bigint(8)
|
||||
# header_file_size :integer
|
||||
# header_updated_at :datetime
|
||||
# avatar_remote_url :string
|
||||
# subscription_expires_at :datetime
|
||||
@@ -35,7 +36,6 @@
|
||||
# shared_inbox_url :string default(""), not null
|
||||
# followers_url :string default(""), not null
|
||||
# protocol :integer default(0), not null
|
||||
# id :bigint(8) not null, primary key
|
||||
# memorial :boolean default(FALSE), not null
|
||||
# moved_to_account_id :bigint(8)
|
||||
# featured_collection_url :string
|
||||
@@ -43,10 +43,10 @@
|
||||
# actor_type :string
|
||||
# discoverable :boolean
|
||||
# also_known_as :string is an Array
|
||||
# is_pro :boolean default(FALSE), not null
|
||||
# pro_expires_at :datetime
|
||||
# silenced_at :datetime
|
||||
# suspended_at :datetime
|
||||
# is_pro :boolean default(FALSE), not null
|
||||
# pro_expires_at :datetime
|
||||
# is_verified :boolean default(FALSE), not null
|
||||
# is_donor :boolean default(FALSE), not null
|
||||
# is_investor :boolean default(FALSE), not null
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ApplicationRecord < ActiveRecord::Base
|
||||
connects_to database: {
|
||||
writing: :master,
|
||||
reading: :slave1
|
||||
}
|
||||
self.abstract_class = true
|
||||
include Remotable
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# user_id :bigint(8)
|
||||
# dump_file_name :string
|
||||
# dump_content_type :string
|
||||
# dump_file_size :bigint(8)
|
||||
# dump_file_size :integer
|
||||
# dump_updated_at :datetime
|
||||
# processed :boolean default(FALSE), not null
|
||||
# created_at :datetime not null
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# domain :string
|
||||
# image_file_name :string
|
||||
# image_content_type :string
|
||||
# image_file_size :bigint(8)
|
||||
# image_file_size :integer
|
||||
# image_updated_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
# description :string not null
|
||||
# cover_image_file_name :string
|
||||
# cover_image_content_type :string
|
||||
# cover_image_file_size :bigint(8)
|
||||
# cover_image_file_size :integer
|
||||
# cover_image_updated_at :datetime
|
||||
# is_nsfw :boolean default(FALSE), not null
|
||||
# is_featured :boolean default(FALSE), not null
|
||||
@@ -18,7 +18,7 @@
|
||||
# member_count :integer default(0)
|
||||
# slug :text
|
||||
# is_private :boolean default(FALSE)
|
||||
# is_visible :boolean default(TRUE)
|
||||
# is_visible :boolean default(FALSE)
|
||||
# tags :string default([]), is an Array
|
||||
# password :string
|
||||
# group_category_id :integer
|
||||
|
||||
@@ -8,7 +8,9 @@ class HomeFeed < Feed
|
||||
end
|
||||
|
||||
def get(limit = 20, max_id = nil, since_id = nil, min_id = nil)
|
||||
from_database(limit, max_id, since_id, min_id)
|
||||
ActiveRecord::Base.connected_to(role: :reading) do
|
||||
from_database(limit, max_id, since_id, min_id)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
# id :bigint(8) not null, primary key
|
||||
# list_id :bigint(8) not null
|
||||
# account_id :bigint(8) not null
|
||||
# follow_id :bigint(8)
|
||||
# follow_id :bigint(8) default(1)
|
||||
#
|
||||
|
||||
class ListAccount < ApplicationRecord
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
#
|
||||
# Table name: media_attachments
|
||||
#
|
||||
# id :bigint(8) not null, primary key
|
||||
# status_id :bigint(8)
|
||||
# file_file_name :string
|
||||
# file_content_type :string
|
||||
# file_file_size :bigint(8)
|
||||
# file_file_size :integer
|
||||
# file_updated_at :datetime
|
||||
# remote_url :string default(""), not null
|
||||
# created_at :datetime not null
|
||||
@@ -15,7 +16,6 @@
|
||||
# type :integer default("image"), not null
|
||||
# file_meta :json
|
||||
# account_id :bigint(8)
|
||||
# id :bigint(8) not null, primary key
|
||||
# description :text
|
||||
# scheduled_status_id :bigint(8)
|
||||
# blurhash :string
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
# description :string default(""), not null
|
||||
# image_file_name :string
|
||||
# image_content_type :string
|
||||
# image_file_size :bigint(8)
|
||||
# image_file_size :integer
|
||||
# image_updated_at :datetime
|
||||
# type :integer default("link"), not null
|
||||
# html :text default(""), not null
|
||||
|
||||
@@ -44,10 +44,13 @@ class SessionActivation < ApplicationRecord
|
||||
end
|
||||
|
||||
def activate(**options)
|
||||
SessionActivation.record_timestamps = true
|
||||
activation = create!(options)
|
||||
purge_old
|
||||
SessionActivation.record_timestamps = false
|
||||
activation = nil
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
SessionActivation.record_timestamps = true
|
||||
activation = create!(options)
|
||||
purge_old
|
||||
SessionActivation.record_timestamps = false
|
||||
end
|
||||
activation
|
||||
end
|
||||
|
||||
@@ -72,12 +75,16 @@ class SessionActivation < ApplicationRecord
|
||||
end
|
||||
|
||||
def assign_access_token
|
||||
superapp = Doorkeeper::Application.find_by(superapp: true)
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
|
||||
self.access_token = Doorkeeper::AccessToken.create!(application_id: superapp&.id,
|
||||
resource_owner_id: user_id,
|
||||
scopes: 'read write follow',
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?)
|
||||
superapp = Doorkeeper::Application.find_by(superapp: true)
|
||||
|
||||
self.access_token = Doorkeeper::AccessToken.create!(application_id: superapp&.id,
|
||||
resource_owner_id: user_id,
|
||||
scopes: 'read write follow',
|
||||
expires_in: Doorkeeper.configuration.access_token_expires_in,
|
||||
use_refresh_token: Doorkeeper.configuration.refresh_token_enabled?)
|
||||
end
|
||||
self.access_token
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
# var :string default(""), not null
|
||||
# file_file_name :string
|
||||
# file_content_type :string
|
||||
# file_file_size :bigint(8)
|
||||
# file_file_size :integer
|
||||
# file_updated_at :datetime
|
||||
# meta :json
|
||||
# created_at :datetime not null
|
||||
|
||||
@@ -155,26 +155,34 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_tracked_fields!(request)
|
||||
super
|
||||
prepare_returning_user!
|
||||
ru = nil
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
super
|
||||
ru = prepare_returning_user!
|
||||
end
|
||||
ru
|
||||
end
|
||||
|
||||
def update_sign_in!(request, new_sign_in: false)
|
||||
old_current, new_current = current_sign_in_at, Time.now.utc
|
||||
self.last_sign_in_at = old_current || new_current
|
||||
self.current_sign_in_at = new_current
|
||||
ru = nil
|
||||
ActiveRecord::Base.connected_to(role: :writing) do
|
||||
old_current, new_current = current_sign_in_at, Time.now.utc
|
||||
self.last_sign_in_at = old_current || new_current
|
||||
self.current_sign_in_at = new_current
|
||||
|
||||
old_current, new_current = current_sign_in_ip, request.remote_ip
|
||||
self.last_sign_in_ip = old_current || new_current
|
||||
self.current_sign_in_ip = new_current
|
||||
old_current, new_current = current_sign_in_ip, request.remote_ip
|
||||
self.last_sign_in_ip = old_current || new_current
|
||||
self.current_sign_in_ip = new_current
|
||||
|
||||
if new_sign_in
|
||||
self.sign_in_count ||= 0
|
||||
self.sign_in_count += 1
|
||||
if new_sign_in
|
||||
self.sign_in_count ||= 0
|
||||
self.sign_in_count += 1
|
||||
end
|
||||
|
||||
save(validate: false) unless new_record?
|
||||
ru = prepare_returning_user!
|
||||
end
|
||||
|
||||
save(validate: false) unless new_record?
|
||||
prepare_returning_user!
|
||||
ru
|
||||
end
|
||||
|
||||
def disable_two_factor!
|
||||
@@ -233,6 +241,7 @@ class User < ApplicationRecord
|
||||
end
|
||||
|
||||
def web_push_subscription(session)
|
||||
return nil if session.nil?
|
||||
session.web_push_subscription.nil? ? nil : session.web_push_subscription
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user