I’m writing a small app on python using Mysql DB.
Could you tell me please is this method is viable?
I’m just not sure if I should every time ask a DB for some data, knowing nothing has changed since the last call. This way I technically can reduce the excessive work, though it feels VERY wrong
def update(sub=False, adm=False, bkl=False, dct=False, usr=False) -> None:
global subscribers, admins, blacklist, dictionary, users
if sub:
cursor.execute("SELECT id FROM users WHERE is_subscribed = TRUE")
subscribers = [i[0] for i in cursor.fetchall()]
if adm:
cursor.execute("SELECT id FROM users WHERE is_admin = TRUE")
admins = [i[0] for i in cursor.fetchall()]
if bkl:
cursor.execute("SELECT id FROM users WHERE is_banned = TRUE")
blacklist = [i[0] for i in cursor.fetchall()]
if usr:
cursor.execute("SELECT id FROM users")
users = [i[0] for i in cursor.fetchall()]
if dct:
cursor.execute("SELECT ukr, rus FROM vocabulary")
dictionary = alphabet_sort([(k, v) for k, v in cursor.fetchall()])
Thank you in advance.