don't store post body

This commit is contained in:
codl 2017-08-20 18:05:01 +02:00
parent fc58833bf5
commit b63f2f2b06
No known key found for this signature in database
GPG Key ID: 6CD7C8891ED1233A
4 changed files with 25 additions and 12 deletions

View File

@ -124,7 +124,6 @@ def post_from_api_object(obj, instance):
return Post(
mastodon_instance = instance,
mastodon_id = obj['id'],
body = obj['content'],
favourite = obj['favourited'],
has_media = 'media_attachments' in obj and bool(obj['media_attachments']),
created_at = iso8601.parse_date(obj['created_at']),

View File

@ -90,10 +90,6 @@ def post_from_api_tweet_object(tweet, post=None):
except ValueError:
post.created_at = datetime.strptime(tweet['created_at'], '%Y-%m-%d %H:%M:%S %z')
#whyyy
if 'full_text' in tweet:
post.body = tweet['full_text']
else:
post.body = tweet['text']
post.author_id = 'twitter:{}'.format(tweet['user']['id_str'])
if 'favorited' in tweet:
post.favourite = tweet['favorited']

View File

@ -0,0 +1,24 @@
"""remove post body
Revision ID: 8993e80e7aa3
Revises: c80af843eed3
Create Date: 2017-08-20 18:04:28.516129
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '8993e80e7aa3'
down_revision = 'c80af843eed3'
branch_labels = None
depends_on = None
def upgrade():
op.drop_column('posts', 'body')
def downgrade():
op.add_column('posts', sa.Column('body', sa.VARCHAR(), autoincrement=False, nullable=True))

View File

@ -169,7 +169,6 @@ class Post(db.Model, TimestampMixin, RemoteIDMixin):
__tablename__ = 'posts'
id = db.Column(db.String, primary_key=True)
body = db.Column(db.String)
author_id = db.Column(db.String, db.ForeignKey('accounts.id', ondelete='CASCADE', onupdate='CASCADE'), nullable=False)
author = db.relationship(Account,
@ -178,13 +177,8 @@ class Post(db.Model, TimestampMixin, RemoteIDMixin):
favourite = db.Column(db.Boolean, server_default='FALSE', nullable=False)
has_media = db.Column(db.Boolean, server_default='FALSE', nullable=False)
def snippet(self):
if len(self.body) > 20:
return self.body[:19] + ""
return self.body
def __repr__(self):
return '<Post ({}, "{}", Author: {})>'.format(self.id, self.snippet(), self.author_id)
return '<Post ({}, Author: {})>'.format(self.id, self.author_id)
db.Index('ix_posts_author_id_created_at', Post.author_id, Post.created_at)