Permalink
Browse files

Merge pull request #195 from taedixon/recently-active

Add `latest_submission_time` column to profile
  • Loading branch information...
2 parents 056a0ae + 90f7e88 commit bd8a7610a1e12b8fbfd3e8f5ebc8e96291a366c3 @hyena hyena committed on GitHub Jan 7, 2017
@@ -0,0 +1,34 @@
+"""Track most recent submission time on profile
+
+Used to prevent scans on submission for determining when
+a user most recently posted something, for ordering
+marketplace search results
+
+Revision ID: 83e6b2a46191
+Revises: a49795aa2584
+Create Date: 2017-01-07 03:21:10.114125
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '83e6b2a46191'
+down_revision = 'a49795aa2584'
+
+from alembic import op
+import sqlalchemy as sa
+import libweasyl
+
+
+def upgrade():
+ op.add_column('profile', sa.Column('latest_submission_time', libweasyl.models.helpers.WeasylTimestampColumn(),
+ nullable=False, server_default='0'))
+ op.execute("""
+ UPDATE profile p SET latest_submission_time = (
+ SELECT COALESCE(MAX(s.unixtime), 0) AS latest FROM submission s WHERE s.userid = p.userid
+ )
+ """)
+
+
+def downgrade():
+ op.drop_column('profile', 'latest_submission_time')
+ pass
@@ -524,6 +524,7 @@ def default_fkey(*args, **kwargs):
Column('catchphrase', String(length=200), nullable=False, server_default=''),
Column('artist_type', String(length=100), nullable=False, server_default=''),
Column('unixtime', WeasylTimestampColumn(), nullable=False),
+ Column('latest_submission_time', WeasylTimestampColumn(), nullable=False, server_default='0'),
Column('profile_text', Text(), nullable=False, server_default=''),
Column('settings', String(length=20), nullable=False, server_default='ccci'),
Column('stream_url', String(length=500), nullable=False, server_default=''),
@@ -126,10 +126,14 @@ def create_generic(userid, submission, **kwargs):
profile.check_user_rating_allowed(userid, submission.rating)
- return create_specific(
+ newid = create_specific(
userid=userid,
submission=submission,
**kwargs)
+ if newid:
+ p = d.meta.tables['profile']
+ d.connect().execute(p.update().where(p.c.userid == userid).values(latest_submission_time=arrow.utcnow()))
+ return newid
return create_generic
@@ -23,6 +23,13 @@ def add_entity(entity):
return entity
+def update_last_submission_time(userid, unixtime):
+ profile = d.meta.tables['profile']
+ db = d.connect()
+ db.execute(profile.update().where(profile.c.userid == userid).values(latest_submission_time=unixtime))
+ db.flush()
+
+
def create_api_key(userid, token, description=""):
add_entity(orm.APIToken(userid=userid, token=token, description=description))
@@ -79,6 +86,7 @@ def create_submission(userid, title="", rating=ratings.GENERAL.code, unixtime=ar
submission = add_entity(content.Submission(
userid=userid, rating=rating, title=title, unixtime=unixtime, content=description,
folderid=folderid, subtype=subtype, sorttime=arrow.get(0), settings=settings))
+ update_last_submission_time(userid, unixtime)
return submission.submitid
@@ -128,6 +136,7 @@ def create_shout(userid, targetid, parentid=None, body="",
def create_journal(userid, title='', rating=ratings.GENERAL.code, unixtime=arrow.get(1), settings=None):
journal = add_entity(content.Journal(
userid=userid, title=title, rating=rating, unixtime=unixtime, settings=settings))
+ update_last_submission_time(userid, unixtime)
return journal.journalid
@@ -143,6 +152,7 @@ def create_character(userid, name='', age='', gender='', height='', weight='', s
character = add_entity(content.Character(
userid=userid, char_name=name, age=age, gender=gender, height=height, weight=weight,
species=species, content=description, rating=rating, unixtime=unixtime, settings=settings))
+ update_last_submission_time(userid, unixtime)
return character.charid

0 comments on commit bd8a761

Please sign in to comment.