mirror of
https://github.com/tcsenpai/swingmusic.git
synced 2025-07-29 14:12:21 +00:00
fix: prevent duplicate favorite items
This commit is contained in:
parent
6b1cac3892
commit
728f4b8649
@ -5,11 +5,26 @@ from .utils import SQLiteManager
|
|||||||
class SQLiteFavoriteMethods:
|
class SQLiteFavoriteMethods:
|
||||||
"""THis class contains methods for interacting with the favorites table."""
|
"""THis class contains methods for interacting with the favorites table."""
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def check_is_favorite(cls, itemhash: str, fav_type: str):
|
||||||
|
"""
|
||||||
|
Checks if an item is favorited.
|
||||||
|
"""
|
||||||
|
sql = """SELECT * FROM favorites WHERE hash = ? AND type = ?"""
|
||||||
|
with SQLiteManager(userdata_db=True) as cur:
|
||||||
|
cur.execute(sql, (itemhash, fav_type))
|
||||||
|
items = cur.fetchall()
|
||||||
|
return len(items) > 0
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def insert_one_favorite(cls, fav_type: str, fav_hash: str):
|
def insert_one_favorite(cls, fav_type: str, fav_hash: str):
|
||||||
"""
|
"""
|
||||||
Inserts a single favorite into the database.
|
Inserts a single favorite into the database.
|
||||||
"""
|
"""
|
||||||
|
# try to find the favorite in the database, if it exists, don't insert it
|
||||||
|
if cls.check_is_favorite(fav_hash, fav_type):
|
||||||
|
return
|
||||||
|
|
||||||
sql = """INSERT INTO favorites(type, hash) VALUES(?,?)"""
|
sql = """INSERT INTO favorites(type, hash) VALUES(?,?)"""
|
||||||
with SQLiteManager(userdata_db=True) as cur:
|
with SQLiteManager(userdata_db=True) as cur:
|
||||||
cur.execute(sql, (fav_type, fav_hash))
|
cur.execute(sql, (fav_type, fav_hash))
|
||||||
@ -64,14 +79,3 @@ class SQLiteFavoriteMethods:
|
|||||||
|
|
||||||
with SQLiteManager(userdata_db=True) as cur:
|
with SQLiteManager(userdata_db=True) as cur:
|
||||||
cur.execute(sql, (fav_hash, fav_type))
|
cur.execute(sql, (fav_hash, fav_type))
|
||||||
|
|
||||||
@classmethod
|
|
||||||
def check_is_favorite(cls, itemhash: str, fav_type: str):
|
|
||||||
"""
|
|
||||||
Checks if an item is favorited.
|
|
||||||
"""
|
|
||||||
sql = """SELECT * FROM favorites WHERE hash = ? AND type = ?"""
|
|
||||||
with SQLiteManager(userdata_db=True) as cur:
|
|
||||||
cur.execute(sql, (itemhash, fav_type))
|
|
||||||
items = cur.fetchall()
|
|
||||||
return len(items) > 0
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user