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

Use materialized views for all charts #419

Open
jace opened this issue Feb 27, 2018 · 7 comments
Open

Use materialized views for all charts #419

jace opened this issue Feb 27, 2018 · 7 comments

Comments

@jace
Copy link
Member

jace commented Feb 27, 2018

In the spirit of #418, materialized views can be used wherever we have expensive queries that collate data for a day, week or month. These include:

  1. The statistics chart for job posts
  2. The statistics chart for campaigns
  3. The admin dashboard graphs for hourly (48h) and daily (2 weeks)
  4. The admin historical dashboard
@jace
Copy link
Member Author

jace commented Feb 27, 2018

@iambibhas
Copy link
Contributor

@jace creating the mviews need a call to create_all() or Table.create(). What's the best way to do this that you can think of, so that we dont have to call it manually every time something changes? migrations? but then we'll have to import the mview models to migrations.

@jace
Copy link
Member Author

jace commented Feb 28, 2018

Migrations, and always make a copy of the model in the migration.

@iambibhas
Copy link
Contributor

I went through that link and the method to declare views in sqlalchemy all of last week. But it seems sqlalchemy doesn't really work anymore like it's described there. Even when I got it to create the mviews, it'll still try to create a table with the given columns from the query.

From my previous experience, I think it might be enough to -

  1. write a Model class with the columns defined and the query in a private variable just for reference
  2. find a way to make alembic ignore that model and write migration to actually create the mviews
  3. leave comment in the mview model class that - If we ever need to change the query in the mview, then just write another migration dropping and recreating the mview with the new query

@jace
Copy link
Member Author

jace commented Mar 5, 2018

This won't work because we don't use Alembic for new deployments. See point 6 in hasgeek/coaster#100.

@jace
Copy link
Member Author

jace commented Mar 5, 2018

Have you tried using __abstract__ to prevent table creation? http://docs.sqlalchemy.org/en/latest/orm/inheritance.html?highlight=abstract#abstract-concrete-classes

@iambibhas
Copy link
Contributor

I know about abstract, I haven't checked if abstract models can be queried just like regular models in sqlalchemy or if there is any limitation internally.

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