From 761462ef930fa8ac1094629b403d0ec09bb5c0ab Mon Sep 17 00:00:00 2001 From: vera-liu Date: Tue, 10 Jan 2017 16:58:19 -0800 Subject: [PATCH] Revert "#views users for created dashboards on profile page" (#1943) * Revert "#views users for created dashboards on profile page" * Change the downversion after after-version * Update models.py --- .../profile/components/CreatedContent.jsx | 6 +- .../versions/1296d28ec131_druid_exports.py | 4 +- superset/migrations/versions/1b2c3f7c96f9_.py | 64 ------------------- superset/models.py | 10 ++- superset/views.py | 16 ++--- 5 files changed, 16 insertions(+), 84 deletions(-) delete mode 100644 superset/migrations/versions/1b2c3f7c96f9_.py diff --git a/superset/assets/javascripts/profile/components/CreatedContent.jsx b/superset/assets/javascripts/profile/components/CreatedContent.jsx index 96978756d3fa2..d779e19892178 100644 --- a/superset/assets/javascripts/profile/components/CreatedContent.jsx +++ b/superset/assets/javascripts/profile/components/CreatedContent.jsx @@ -19,7 +19,6 @@ class CreatedContent extends React.PureComponent { renderSliceTable() { const mutator = (data) => data.map(slice => ({ slice: {slice.title}, - views: slice.views, favorited: moment.utc(slice.dttm).fromNow(), _favorited: slice.dttm, })); @@ -27,7 +26,7 @@ class CreatedContent extends React.PureComponent { data.map(dash => ({ dashboard: {dash.title}, - views: dash.views, favorited: moment.utc(dash.dttm).fromNow(), _favorited: dash.dttm, })); @@ -47,7 +45,7 @@ class CreatedContent extends React.PureComponent { mutator={mutator} dataEndpoint={`/superset/created_dashboards/${this.props.user.userId}/`} noDataText="No dashboards" - columns={['dashboard', 'favorited', 'views']} + columns={['dashboard', 'favorited']} sortable /> ); diff --git a/superset/migrations/versions/1296d28ec131_druid_exports.py b/superset/migrations/versions/1296d28ec131_druid_exports.py index 9005c03904e7f..6df37bcda5931 100644 --- a/superset/migrations/versions/1296d28ec131_druid_exports.py +++ b/superset/migrations/versions/1296d28ec131_druid_exports.py @@ -1,14 +1,14 @@ """Adds params to the datasource (druid) table Revision ID: 1296d28ec131 -Revises: e46f2d27a08e +Revises: 6414e83d82b7 Create Date: 2016-12-06 17:40:40.389652 """ # revision identifiers, used by Alembic. revision = '1296d28ec131' -down_revision = '1b2c3f7c96f9' +down_revision = '6414e83d82b7' from alembic import op import sqlalchemy as sa diff --git a/superset/migrations/versions/1b2c3f7c96f9_.py b/superset/migrations/versions/1b2c3f7c96f9_.py deleted file mode 100644 index 0e1a1379de0e4..0000000000000 --- a/superset/migrations/versions/1b2c3f7c96f9_.py +++ /dev/null @@ -1,64 +0,0 @@ -"""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') diff --git a/superset/models.py b/superset/models.py index f906f23f5a2cf..c52373bd38c79 100644 --- a/superset/models.py +++ b/superset/models.py @@ -243,7 +243,6 @@ class Slice(Model, AuditMixinNullable, ImportMixin): cache_timeout = Column(Integer) perm = Column(String(1000)) owners = relationship("User", secondary=slice_user) - views = Column(Integer, default=1) export_fields = ('slice_name', 'datasource_type', 'datasource_name', 'viz_type', 'params', 'cache_timeout') @@ -442,9 +441,9 @@ class Dashboard(Model, AuditMixinNullable, ImportMixin): slices = relationship( 'Slice', secondary=dashboard_slices, backref='dashboards') owners = relationship("User", secondary=dashboard_user) + export_fields = ('dashboard_title', 'position_json', 'json_metadata', 'description', 'css', 'slug') - views = Column(Integer, default=1) def __repr__(self): return self.dashboard_title @@ -2554,8 +2553,8 @@ class Log(Model): id = Column(Integer, primary_key=True) action = Column(String(512)) user_id = Column(Integer, ForeignKey('ab_user.id')) - dashboard_id = Column(Integer, ForeignKey('dashboards.id')) - slice_id = Column(Integer, ForeignKey('slices.id')) + dashboard_id = Column(Integer) + slice_id = Column(Integer) json = Column(Text) user = relationship('User', backref='logs', foreign_keys=[user_id]) dttm = Column(DateTime, default=datetime.utcnow) @@ -2596,8 +2595,7 @@ def wrapper(*args, **kwargs): datetime.now() - start_dttm).total_seconds() * 1000, referrer=request.referrer[:1000] if request.referrer else None, user_id=user_id) - db.session.add(log) - db.session.commit() + db.session.flush() return value return wrapper diff --git a/superset/views.py b/superset/views.py index f5ddf7ff77d22..78bf906b0ea1b 100755 --- a/superset/views.py +++ b/superset/views.py @@ -1444,8 +1444,6 @@ def explore(self, datasource_type, datasource_id): if slice_id: slc = db.session.query(models.Slice).filter_by(id=slice_id).first() - slc.views = slc.views + 1 - db.session.commit() error_redirect = '/slicemodelview/list/' datasource_class = SourceRegistry.sources[datasource_type] @@ -1963,7 +1961,10 @@ def created_dashboards(self, user_id): Dash, ) .filter( - Dash.created_by_fk == user_id, + sqla.or_( + Dash.created_by_fk == user_id, + Dash.changed_by_fk == user_id, + ) ) .order_by( Dash.changed_on.desc() @@ -1975,7 +1976,6 @@ def created_dashboards(self, user_id): 'title': o.dashboard_title, 'url': o.url, 'dttm': o.changed_on, - 'views': o.views, } for o in qry.all()] return Response( json.dumps(payload, default=utils.json_int_dttm_ser), @@ -1990,7 +1990,10 @@ def created_slices(self, user_id): qry = ( db.session.query(Slice) .filter( - Slice.created_by_fk == user_id, + sqla.or_( + Slice.created_by_fk == user_id, + Slice.changed_by_fk == user_id, + ) ) .order_by(Slice.changed_on.desc()) ) @@ -1999,7 +2002,6 @@ def created_slices(self, user_id): 'title': o.slice_name, 'url': o.slice_url, 'dttm': o.changed_on, - 'views': o.views, } for o in qry.all()] return Response( json.dumps(payload, default=utils.json_int_dttm_ser), @@ -2136,8 +2138,6 @@ def dashboard(self, dashboard_id): qry = qry.filter_by(slug=dashboard_id) dash = qry.one() - dash.views = dash.views + 1 - db.session.commit() datasources = {slc.datasource for slc in dash.slices} for datasource in datasources: if not self.datasource_access(datasource):