refactor(llm): centralize usage persistence
This commit is contained in:
@@ -226,27 +226,6 @@ class AccountRepository:
|
||||
def delete_profile(connection: sqlite3.Connection, user_id: int) -> None:
|
||||
connection.execute("DELETE FROM birth_profiles WHERE user_id = ?", (user_id,))
|
||||
|
||||
@staticmethod
|
||||
def usage_today(connection: sqlite3.Connection, user_id: int, usage_date: str) -> int:
|
||||
row = connection.execute(
|
||||
"""
|
||||
SELECT successful_calls FROM llm_usage_daily
|
||||
WHERE user_id = ? AND usage_date = ?
|
||||
""",
|
||||
(user_id, usage_date),
|
||||
).fetchone()
|
||||
return int(row["successful_calls"]) if row else 0
|
||||
|
||||
@staticmethod
|
||||
def usage_for_users(connection: sqlite3.Connection, usage_date: str) -> dict[int, int]:
|
||||
return {
|
||||
int(row["user_id"]): int(row["successful_calls"])
|
||||
for row in connection.execute(
|
||||
"SELECT user_id, successful_calls FROM llm_usage_daily WHERE usage_date = ?",
|
||||
(usage_date,),
|
||||
)
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def list_memberships(connection: sqlite3.Connection) -> tuple[MembershipAccount, ...]:
|
||||
rows = connection.execute(
|
||||
|
||||
Reference in New Issue
Block a user