Skip to content

Commit

Permalink
optimize indexes for table hive_bookmarks and other minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
only-dev-time committed May 26, 2024
1 parent c863303 commit 05a2b27
Showing 5 changed files with 7 additions and 10 deletions.
6 changes: 3 additions & 3 deletions hive/db/schema.py
Original file line number Diff line number Diff line change
@@ -364,14 +364,14 @@ def build_metadata_bookmarks(metadata=None):

sa.Table(
'hive_bookmarks', metadata,
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), # TODO notwendig?
sa.Column('account', VARCHAR(16), nullable=False),
sa.Column('post_id', sa.Integer, nullable=False),
sa.Column('bookmarked_at', sa.DateTime, nullable=False),

sa.UniqueConstraint('account', 'post_id', name='hive_bookmarks_ux1'),
sa.Index('hive_bookmarks_ix1', 'account'), # bookmarks from account
sa.Index('hive_bookmarks_ix2', 'post_id'), # bookmarks for a post
sa.Index('hive_bookmarks_ix1', 'post_id'),
sa.Index('hive_bookmarks_ix2', 'account', 'post_id'),
sa.Index('hive_bookmarks_ix3', 'account', 'bookmarked_at'),
)

return metadata
3 changes: 0 additions & 3 deletions hive/indexer/bookmark.py
Original file line number Diff line number Diff line change
@@ -26,15 +26,12 @@ def bookmark_op(cls, account, op_json, date):
sql = """INSERT INTO hive_bookmarks (account, post_id, bookmarked_at)
VALUES (:account, :post_id, :at)"""
DB.query(sql, **op)
# TODO notify author of bookmark added
# TODO update bookmarks count on post

# perform remove bookmark
elif op['action'] == 'remove':
sql = """DELETE FROM hive_bookmarks
WHERE account = :account AND post_id = :post_id"""
DB.query(sql, **op)
# TODO update bookmarks count on post

@classmethod
def _validated_op(cls, account, op, date):
2 changes: 1 addition & 1 deletion hive/indexer/custom_op.py
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ def _process_legacy(cls, account, op_json, block_date):
author: {type: 'account'},
permlink: {type: 'permlink'},
action: {type: 'str'},
category: {type: 'str'}}
category: {type: 'str'}} // category currently unused
"""
if not isinstance(op_json, list):
return
3 changes: 1 addition & 2 deletions hive/server/bridge_api/cursor.py
Original file line number Diff line number Diff line change
@@ -469,7 +469,6 @@ async def pids_by_payout(db, account: str, start_author: str = '',
async def pids_by_bookmarks(db, account: str, sort: str = 'bookmarks', category: str = '', start_author: str = '',
start_permlink: str = '', limit: int = 20):
"""Get a list of post_ids for an author's bookmarks."""
account_id = await _get_account_id(db, account)
seek = ''
join = ''
start_id = await _get_post_id(db, start_author, start_permlink) if start_permlink else None
@@ -508,7 +507,7 @@ async def pids_by_bookmarks(db, account: str, sort: str = 'bookmarks', category:
SELECT bookmarks.post_id
FROM hive_bookmarks AS bookmarks
%s
WHERE account = :account %s
WHERE bookmarks.account = :account %s
ORDER BY %s
LIMIT :limit
""" % (join, seek, order_by)
3 changes: 2 additions & 1 deletion hive/server/bridge_api/methods.py
Original file line number Diff line number Diff line change
@@ -172,7 +172,8 @@ async def get_bookmarked_posts(context, account, sort='bookmarks', category='',
start_author = valid_account(start_author, allow_empty=True)
start_permlink = valid_permlink(start_permlink, allow_empty=True)
start = (start_author, start_permlink)
limit = valid_limit(limit, 100)
limit = valid_limit(limit, 50)
category = '' # currently unused

# check blacklist accounts
_id = await db.query_one("SELECT id FROM hive_posts_status WHERE author = :n AND list_type = '3'", n=account)

0 comments on commit 05a2b27

Please sign in to comment.