Skip to content

Commit f8ec2fc

Browse files
author
Isaac Solo
authored
Add entity counts (#5583)
1 parent 389b176 commit f8ec2fc

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
from src.models.playlists.playlist import Playlist
3+
from src.models.social.follow import Follow
4+
from src.models.social.repost import Repost
5+
from src.models.social.save import Save
6+
from src.models.tracks.track import Track
7+
from src.models.users.user import User
8+
from src.utils import db_session
9+
from src.utils.structured_logger import StructuredLogger
10+
11+
logger = StructuredLogger(__name__)
12+
13+
14+
def get_entities_count_check():
15+
"""
16+
Gets counts for each of these entities.
17+
"""
18+
db = db_session.get_db_read_replica()
19+
with db.scoped_session() as session:
20+
user_counts = session.query(User).filter(User.is_current).count()
21+
track_counts = session.query(Track).filter(Track.is_current).count()
22+
playlist_counts = session.query(Playlist).filter(Playlist.is_current).count()
23+
repost_counts = session.query(Repost).filter(Repost.is_current).count()
24+
save_counts = session.query(Save).filter(Save.is_current).count()
25+
follow_counts = session.query(Follow).filter(Follow.is_current).count()
26+
res = {
27+
"user_counts": user_counts,
28+
"track_counts": track_counts,
29+
"playlist_counts": playlist_counts,
30+
"repost_counts": repost_counts,
31+
"save_counts": save_counts,
32+
"follow_counts": follow_counts
33+
}
34+
return res

discovery-provider/src/queries/health_check.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from src.queries.get_latest_play import get_latest_play
1111
from src.queries.get_sol_plays import get_latest_sol_play_check_info
1212
from src.queries.get_trusted_notifier_discrepancies import get_trusted_notifier_discrepancies
13+
from src.queries.get_entities_count_check import get_entities_count_check
1314
from src.queries.queries import parse_bool_param
1415
from src.tasks.index_profile_challenge_backfill import (
1516
index_profile_challenge_backfill_tablename,
@@ -71,6 +72,12 @@ def trusted_notifier_discrepancies_check():
7172
return success_response(health_results, 500 if error else 200, sign_response=False)
7273

7374

75+
@bp.route("/entities_count_check", methods=["GET"])
76+
def entities_count_check():
77+
res_count = get_entities_count_check()
78+
return success_response(res_count)
79+
80+
7481
# Health check for block diff between DB and chain.
7582
@bp.route("/block_check", methods=["GET"])
7683
def block_check():

0 commit comments

Comments
 (0)