-
Notifications
You must be signed in to change notification settings - Fork 131
fix trending with core #11525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix trending with core #11525
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
|
|
||
| from src.challenges.challenge_event import ChallengeEvent | ||
| from src.challenges.challenge_event_bus import ChallengeEventBus | ||
| from src.models.core.core_indexed_blocks import CoreIndexedBlocks | ||
| from src.queries.get_trending_playlists import ( | ||
| GetTrendingPlaylistsArgs, | ||
| _get_trending_playlists_with_session, | ||
|
|
@@ -19,9 +20,11 @@ | |
| _get_underground_trending_with_session, | ||
| ) | ||
| from src.tasks.aggregates import get_latest_blocknumber | ||
| from src.tasks.core.core_client import get_core_instance | ||
| from src.trending_strategies.trending_strategy_factory import TrendingStrategyFactory | ||
| from src.trending_strategies.trending_type_and_version import TrendingType | ||
| from src.utils import helpers | ||
| from src.utils.core import is_indexing_core_em | ||
| from src.utils.redis_constants import most_recent_indexed_block_redis_key | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
@@ -85,20 +88,43 @@ def enqueue_trending_challenges( | |
| ) | ||
| update_start = time.time() | ||
| with challenge_bus.use_scoped_dispatch_queue(): | ||
| latest_blocknumber = get_latest_blocknumber_via_redis(session, redis) | ||
| # subtract final poa block because db is final_poa_block + latest_acdc_block | ||
| latest_blocknumber = get_latest_blocknumber(session) | ||
| if latest_blocknumber is None: | ||
| logger.error( | ||
| "calculate_trending_challenges.py | Unable to get latest block number" | ||
| ) | ||
| return | ||
|
|
||
| # subtract final poa block because db is final_poa_block + latest_acdc_block | ||
| latest_block_datetime = None | ||
| if is_indexing_core_em(): | ||
| core = get_core_instance() | ||
| node_info = core.get_node_info() | ||
| core_chain_id = node_info.chainid | ||
|
|
||
| latest_indexed_block: Optional[CoreIndexedBlocks] = ( | ||
| session.query(CoreIndexedBlocks) | ||
| .filter(CoreIndexedBlocks.chain_id == core_chain_id) | ||
| .order_by(CoreIndexedBlocks.height.desc()) | ||
| .first() | ||
| ) | ||
|
|
||
| latest_block_datetime = datetime.fromtimestamp( | ||
| web3.eth.get_block(latest_blocknumber - helpers.get_final_poa_block())[ | ||
| "timestamp" | ||
| ] | ||
| ) | ||
| if latest_indexed_block: | ||
| block = core.get_block(int(latest_indexed_block.height)) | ||
| if block: | ||
| latest_block_datetime = block.timestamp.ToDatetime() | ||
| else: | ||
| latest_block_datetime = datetime.fromtimestamp( | ||
| web3.eth.get_block(latest_blocknumber - helpers.get_final_poa_block())[ | ||
| "timestamp" | ||
| ] | ||
| ) | ||
|
Comment on lines
+99
to
+121
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. seems like we just get the latest block for timestamp purposes |
||
|
|
||
| if latest_block_datetime is None: | ||
| logger.error( | ||
| "calculate_trending_challenges.py | Unable to get latest block time" | ||
| ) | ||
| return | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe instead of just returning here, we should throw all the way out to the top level. stuff's wack if we get here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I was following the earlier pattern where if the block was not found then it also returned None. Should we raise an error there too? An indexed block should always return I'd think |
||
|
|
||
| trending_track_versions = trending_strategy_factory.get_versions_for_type( | ||
| TrendingType.TRACKS | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just use the db, indexes should be fast enough and it's easier than keeping redis in sync with db.