Unverified Commit 9adcca26 authored by Benjamin Neff's avatar Benjamin Neff
Browse files

Merge pull request #7533 from SuperTux88/add-indexes

Add missing indexes from #7234
parents cc8fa3e5 dbde75ab
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ If so, please delete it since it will prevent the federation from working proper
* Refactoring single post view interactions [#7182](https://github.com/diaspora/diaspora/pull/7182)
* Update help pages [#7528](https://github.com/diaspora/diaspora/pull/7528)
* Disable rendering logging in production [#7529](https://github.com/diaspora/diaspora/pull/7529)
* Add some missing indexes and cleanup the database if needed [#7533](https://github.com/diaspora/diaspora/pull/7533)

## Bug fixes

+5 −13
Original line number Diff line number Diff line
@@ -5,28 +5,20 @@
class AccountDeletion < ApplicationRecord
  include Diaspora::Federated::Base

  scope :uncompleted, -> { where('completed_at is null') }
  scope :uncompleted, -> { where("completed_at is null") }

  belongs_to :person
  after_commit :queue_delete_account, :on => :create
  after_commit :queue_delete_account, on: :create

  def person=(person)
    self[:diaspora_handle] = person.diaspora_handle
    self[:person_id] = person.id
  end

  def diaspora_handle=(diaspora_handle)
    self[:diaspora_handle] = diaspora_handle
    self[:person_id] ||= Person.find_by_diaspora_handle(diaspora_handle).id
  end
  delegate :diaspora_handle, to: :person

  def queue_delete_account
    Workers::DeleteAccount.perform_async(self.id)
    Workers::DeleteAccount.perform_async(id)
  end

  def perform!
    Diaspora::Federation::Dispatcher.build(person.owner, self).dispatch if person.local?
    AccountDeleter.new(diaspora_handle).perform!
    AccountDeleter.new(person).perform!
  end

  def subscribers
+1 −1
Original line number Diff line number Diff line
@@ -507,7 +507,7 @@ class User < ApplicationRecord
  def close_account!
    self.person.lock_access!
    self.lock_access!
    AccountDeletion.create(:person => self.person)
    AccountDeletion.create(person: person)
  end

  def closed_account?
+19 −0
Original line number Diff line number Diff line
class CleanupAccountDeletionsAndAddUniqueIndex < ActiveRecord::Migration[5.1]
  def up
    remove_column :account_deletions, :diaspora_handle

    duplicate_query = "WHERE a1.person_id = a2.person_id AND a1.id > a2.id"
    if AppConfig.postgres?
      execute("DELETE FROM account_deletions AS a1 USING account_deletions AS a2 #{duplicate_query}")
    else
      execute("DELETE a1 FROM account_deletions a1, account_deletions a2 #{duplicate_query}")
    end

    add_index :account_deletions, :person_id, name: :index_account_deletions_on_person_id, unique: true
  end

  def down
    remove_index :account_deletions, name: :index_account_deletions_on_person_id
    add_column :account_deletions, :diaspora_handle, :string
  end
end
+7 −0
Original line number Diff line number Diff line
class AddMissingIndexes < ActiveRecord::Migration[5.1]
  def change
    add_index :photos, :author_id
    add_index :user_preferences, %i[user_id email_type], length: {email_type: 190}
    add_index :locations, :status_message_id
  end
end
Loading