Skip to content

Commit

Permalink
Rename last_active to latest_submission_time
Browse files Browse the repository at this point in the history
Use submission's given unixtime to update latest_submission_time in tests
  • Loading branch information
taedixon committed Jan 7, 2017
1 parent ca2551c commit 90f7e88
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
Expand Up @@ -20,15 +20,15 @@


def upgrade():
op.add_column('profile', sa.Column('last_active', libweasyl.models.helpers.WeasylTimestampColumn(),
op.add_column('profile', sa.Column('latest_submission_time', libweasyl.models.helpers.WeasylTimestampColumn(),
nullable=False, server_default='0'))
op.execute("""
UPDATE profile p SET last_active = (
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', 'last_active')
op.drop_column('profile', 'latest_submission_time')
pass
2 changes: 1 addition & 1 deletion libweasyl/libweasyl/models/tables.py
Expand Up @@ -524,7 +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('last_active', WeasylTimestampColumn(), nullable=False, server_default='0'),
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=''),
Expand Down
2 changes: 1 addition & 1 deletion weasyl/submission.py
Expand Up @@ -132,7 +132,7 @@ def create_generic(userid, submission, **kwargs):
**kwargs)
if newid:
p = d.meta.tables['profile']
d.connect().execute(p.update().where(p.c.userid == userid).values(last_active=arrow.utcnow()))
d.connect().execute(p.update().where(p.c.userid == userid).values(latest_submission_time=arrow.utcnow()))
return newid

return create_generic
Expand Down
10 changes: 5 additions & 5 deletions weasyl/test/db_utils.py
Expand Up @@ -23,10 +23,10 @@ def add_entity(entity):
return entity


def update_last_active(userid):
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(last_active=arrow.utcnow()))
db.execute(profile.update().where(profile.c.userid == userid).values(latest_submission_time=unixtime))
db.flush()


Expand Down Expand Up @@ -86,7 +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_active(userid)
update_last_submission_time(userid, unixtime)
return submission.submitid


Expand Down Expand Up @@ -136,7 +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_active(userid)
update_last_submission_time(userid, unixtime)
return journal.journalid


Expand All @@ -152,7 +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_active(userid)
update_last_submission_time(userid, unixtime)
return character.charid


Expand Down

0 comments on commit 90f7e88

Please sign in to comment.