docbrown/db/migrate/20190607110030_add_indexes_for_analytics.rb
rhymes a8b7f6eea4 Analytics: refactoring for speed improvements (#3072)
* Use proper auth chain before checking parameters

* Refactor AnalyticsController

* Add a bunch of test and rewrite reactions counts with a single query

* Add tests for follows totals

* Use round and add more refactoring

* Add tests to group by day to fallback during refactoring

* Use group by to calculate comments count by day

* Use group by to calculate follows count by day

* Use group by to calculate reactions stats by day

* Use group by to calculate page_views stats by day

* Move calculations per day back in the cached block

* Add a few comments and a little bit of refactoring

* Add indexes (concurrently) for analytics

* Make tests more time robust

* Use a date range cache related to the requesting user or org

* Freezing time in UTC should help when tests are ran on time zones over the day line

* Remove explicit returns

* Page title is escaped, guard against that

* Move Analytics service spec in the proper place
2019-06-10 09:27:39 -04:00

16 lines
742 B
Ruby

class AddIndexesForAnalytics < ActiveRecord::Migration[5.2]
# transactions are disabled to allow PostgreSQL to add indexes concurrently
disable_ddl_transaction!
def change
# concurrent creation avoids downtime during production deploy because
# indexes get created in the background
add_index :articles, :published, algorithm: :concurrently
add_index :comments, :created_at, algorithm: :concurrently
add_index :comments, :score, algorithm: :concurrently
add_index :follows, :created_at, algorithm: :concurrently
add_index :page_views, :created_at, algorithm: :concurrently
add_index :reactions, :created_at, algorithm: :concurrently
add_index :reactions, :points, algorithm: :concurrently
end
end