-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#views users for created dashboards on profile page (#1667)
* Add #views and #distinct users to created dashboard on profile page * Added index on logs to speed up query * Added #views and #users for slice table * Add a views column to dashboards and slices, prepopulate them with Log data * Remove index on Log model * Remove unused index * Update 1b2c3f7c96f9_.py fix multiple heads * Exclude postgres in prepopulating views column
- Loading branch information
Showing
4 changed files
with
80 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
"""Add number of views as column to dashboards and slices | ||
Revision ID: 1b2c3f7c96f9 | ||
Revises: 6414e83d82b7 | ||
Create Date: 2016-12-15 16:32:31.909331 | ||
""" | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = '1b2c3f7c96f9' | ||
down_revision = '6414e83d82b7' | ||
|
||
from alembic import op | ||
import sqlalchemy as sa | ||
from superset import db, models | ||
|
||
def upgrade(): | ||
op.add_column('dashboards', sa.Column('views', sa.Integer, server_default='1', nullable=True)) | ||
op.add_column('slices', sa.Column('views', sa.Integer, server_default='1', nullable=True)) | ||
|
||
if db.engine.name != 'postgresql': | ||
Dash = models.Dashboard | ||
Log = models.Log | ||
qry = ( | ||
db.session.query( | ||
Dash, | ||
sa.func.count(), | ||
) | ||
.outerjoin(Log) | ||
.filter( | ||
sa.and_( | ||
Log.dashboard_id == Dash.id, | ||
) | ||
) | ||
.group_by(Dash) | ||
) | ||
for dash_obj in qry.all(): | ||
dash_obj[0].views = dash_obj[1] | ||
db.session.commit() | ||
|
||
Slice = models.Slice | ||
qry = ( | ||
db.session.query( | ||
Slice, | ||
sa.func.count(), | ||
) | ||
.outerjoin(Log) | ||
.filter( | ||
sa.and_( | ||
Log.slice_id == Slice.id, | ||
) | ||
) | ||
.group_by(Slice) | ||
) | ||
for slice_obj in qry.all(): | ||
slice_obj[0].views = slice_obj[1] | ||
db.session.commit() | ||
db.session.close() | ||
|
||
|
||
|
||
def downgrade(): | ||
op.drop_column('dashboards', 'views') | ||
op.drop_column('slices', 'views') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters