Skip to content

Commit e9626eb

Browse files
committed
optimize indexes for table hive_bookmarks and other minor fixes
1 parent f074bd4 commit e9626eb

5 files changed

Lines changed: 7 additions & 10 deletions

File tree

hive/db/schema.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -364,14 +364,14 @@ def build_metadata_bookmarks(metadata=None):
364364

365365
sa.Table(
366366
'hive_bookmarks', metadata,
367-
sa.Column('id', sa.Integer, primary_key=True, autoincrement=True), # TODO notwendig?
368367
sa.Column('account', VARCHAR(16), nullable=False),
369368
sa.Column('post_id', sa.Integer, nullable=False),
370369
sa.Column('bookmarked_at', sa.DateTime, nullable=False),
371370

372371
sa.UniqueConstraint('account', 'post_id', name='hive_bookmarks_ux1'),
373-
sa.Index('hive_bookmarks_ix1', 'account'), # bookmarks from account
374-
sa.Index('hive_bookmarks_ix2', 'post_id'), # bookmarks for a post
372+
sa.Index('hive_bookmarks_ix1', 'post_id'),
373+
sa.Index('hive_bookmarks_ix2', 'account', 'post_id'),
374+
sa.Index('hive_bookmarks_ix3', 'account', 'bookmarked_at'),
375375
)
376376

377377
return metadata

hive/indexer/bookmark.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,12 @@ def bookmark_op(cls, account, op_json, date):
2626
sql = """INSERT INTO hive_bookmarks (account, post_id, bookmarked_at)
2727
VALUES (:account, :post_id, :at)"""
2828
DB.query(sql, **op)
29-
# TODO notify author of bookmark added
30-
# TODO update bookmarks count on post
3129

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

3936
@classmethod
4037
def _validated_op(cls, account, op, date):

hive/indexer/custom_op.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def _process_legacy(cls, account, op_json, block_date):
9292
author: {type: 'account'},
9393
permlink: {type: 'permlink'},
9494
action: {type: 'str'},
95-
category: {type: 'str'}}
95+
category: {type: 'str'}} // category currently unused
9696
"""
9797
if not isinstance(op_json, list):
9898
return

hive/server/bridge_api/cursor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ async def pids_by_payout(db, account: str, start_author: str = '',
469469
async def pids_by_bookmarks(db, account: str, sort: str = 'bookmarks', category: str = '', start_author: str = '',
470470
start_permlink: str = '', limit: int = 20):
471471
"""Get a list of post_ids for an author's bookmarks."""
472-
account_id = await _get_account_id(db, account)
473472
seek = ''
474473
join = ''
475474
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:
508507
SELECT bookmarks.post_id
509508
FROM hive_bookmarks AS bookmarks
510509
%s
511-
WHERE account = :account %s
510+
WHERE bookmarks.account = :account %s
512511
ORDER BY %s
513512
LIMIT :limit
514513
""" % (join, seek, order_by)

hive/server/bridge_api/methods.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,8 @@ async def get_bookmarked_posts(context, account, sort='bookmarks', category='',
172172
start_author = valid_account(start_author, allow_empty=True)
173173
start_permlink = valid_permlink(start_permlink, allow_empty=True)
174174
start = (start_author, start_permlink)
175-
limit = valid_limit(limit, 100)
175+
limit = valid_limit(limit, 50)
176+
category = '' # currently unused
176177

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

0 commit comments

Comments
 (0)