PATCH: Fixed database not returning data in recommendations

UPDATE: Decreased polling time to 1 second for later use
This commit is contained in:
white
2025-01-30 10:24:26 +00:00
parent 6586506c97
commit f981b69c94
9 changed files with 77 additions and 55 deletions

View File

@@ -7,8 +7,8 @@ def streamer_live_status(user_id: int) -> bool:
"""
Returns boolean on whether the given streamer is live
"""
with Database() as db:
is_live = db.fetchone("""
db = Database()
is_live = db.fetchone("""
SELECT isLive
FROM streams
WHERE user_id = ?
@@ -19,8 +19,8 @@ def followed_live_streams(user_id: int) -> list[dict]:
"""
Searches for streamers who the user followed which are currently live
"""
with Database() as db:
live_streams = db.fetchall("""
db = Database()
live_streams = db.fetchall("""
SELECT user_id, stream_id, title, num_viewers
FROM streams
WHERE user_id IN (SELECT followed_id FROM follows WHERE user_id = ?)
@@ -33,8 +33,8 @@ def followed_streamers(user_id: int) -> list[dict]:
"""
Returns a list of streamers who the user follows
"""
with Database() as db:
followed_streamers = db.fetchall("""
db = Database()
followed_streamers = db.fetchall("""
SELECT user_id, username
FROM users
WHERE user_id IN (SELECT followed_id FROM follows WHERE user_id = ?);
@@ -45,8 +45,8 @@ def streamer_most_recent_stream(user_id: int) -> dict:
"""
Returns data of the most recent stream by a streamer
"""
with Database() as db:
most_recent_stream = db.fetchone("""
db = Database()
most_recent_stream = db.fetchone("""
SELECT * FROM streams
WHERE user_id = ?
AND stream_id = (SELECT MAX(stream_id) FROM streams WHERE user_id = ?)
@@ -57,8 +57,8 @@ def user_stream(user_id: int, stream_id: int) -> dict:
"""
Returns data of a streamers selected stream
"""
with Database() as db:
stream = db.fetchone("""
db = Database()
stream = db.fetchone("""
SELECT * FROM streams
WHERE user_id = ?
AND stream_id = ?