Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing index for wiki_references causes high loading times #86

Closed
sattlerc opened this issue May 29, 2022 · 3 comments
Closed

Missing index for wiki_references causes high loading times #86

sattlerc opened this issue May 29, 2022 · 3 comments

Comments

@sattlerc
Copy link
Contributor

sattlerc commented May 29, 2022

On page cache expiration (happening after every edit or currently even when a user locks a page by clicking on "edit"), page categories are looked up. An example query is:

SELECT DISTINCT wiki_references.referenced_name
FROM wiki_references LEFT OUTER JOIN pages ON wiki_references.page_id = pages.id
WHERE wiki_references.link_type = 'C' AND pages.web_id = '1';

For larger wikis, this is really slow (3-4s in the case of the nlab), even if there are few pages that live in page categories.

A reason for the slowness is that the table wiki_references doesn't have an index for link_types.
Creating this index solves the problem:

MariaDB [nlab]> create index index_wiki_references_on_link_type on wiki_references (link_type);
Query OK, 10072562 rows affected (2 min 10.78 sec)
Records: 10072562  Duplicates: 0  Warnings: 0

(A more principled solution would be to have a table for page categories.)

@distler
Copy link
Collaborator

distler commented May 29, 2022

The Wiki_References table is, admittedly a bit of a dogs-breakfast. We could have separate tables for each link_type.

But, failing that, here's a Migration that will add the desired index

class AddWikireferenceTypeIndex < ActiveRecord::Migration
  def self.up
    add_index :wiki_references, ["link_type"], :name => "index_wiki_references_on_link_type"
  end

  def self.down
    remove_index :wiki_references, :name => "index_wiki_references_on_link_type"
  end
end

Does that help? If so, I will commit that.

@sattlerc
Copy link
Contributor Author

Looks good!

@distler
Copy link
Collaborator

distler commented May 30, 2022

The migrations are run automatically when you

ruby bundle exec rake upgrade_instiki

Or you can run them manually with

ruby bundle exec rake db:migrate RAILS_ENV=production

I will commit this migration after I release Instiki 0.30.3.

@distler distler closed this as completed May 30, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants