1
0
Fork 0
mirror of synced 2024-10-01 01:36:27 +13:00

Fixed an issue where cache would update even on a get request, causing an infinite loop

This commit is contained in:
Phxntxm 2017-03-19 22:37:45 -05:00
parent 03c91c06ff
commit 542293f8d3

View file

@ -130,13 +130,15 @@ async def add_content(table, content):
# For our purposes however, we do not want this # For our purposes however, we do not want this
try: try:
result = await r.table(table).insert(content).run(conn) result = await r.table(table).insert(content).run(conn)
await conn.close()
except r.ReqlOpFailedError: except r.ReqlOpFailedError:
# This means the table does not exist # This means the table does not exist
await r.table_create(table).run(conn) await r.table_create(table).run(conn)
await r.table(table).insert(content).run(conn) await r.table(table).insert(content).run(conn)
await conn.close()
result = {} result = {}
await conn.close()
if table == 'prefixes' or table == 'server_settings':
loop.create_task(cache[table].update())
return result.get('inserted', 0) > 0 return result.get('inserted', 0) > 0
@ -148,6 +150,7 @@ async def remove_content(table, key):
except r.ReqlOpFailedError: except r.ReqlOpFailedError:
result = {} result = {}
pass pass
await conn.close() await conn.close()
if table == 'prefixes' or table == 'server_settings': if table == 'prefixes' or table == 'server_settings':
loop.create_task(cache[table].update()) loop.create_task(cache[table].update())
@ -164,8 +167,8 @@ async def update_content(table, content, key):
# This is why we're accepting a variable and using it, whatever it may be, as the query # This is why we're accepting a variable and using it, whatever it may be, as the query
result = await r.table(table).get(key).update(content).run(conn) result = await r.table(table).get(key).update(content).run(conn)
except r.ReqlOpFailedError: except r.ReqlOpFailedError:
await conn.close()
result = {} result = {}
await conn.close() await conn.close()
if table == 'prefixes' or table == 'server_settings': if table == 'prefixes' or table == 'server_settings':
loop.create_task(cache[table].update()) loop.create_task(cache[table].update())
@ -179,8 +182,8 @@ async def replace_content(table, content, key):
try: try:
result = await r.table(table).get(key).replace(content).run(conn) result = await r.table(table).get(key).replace(content).run(conn)
except r.ReqlOpFailedError: except r.ReqlOpFailedError:
await conn.close()
result = {} result = {}
await conn.close() await conn.close()
if table == 'prefixes' or table == 'server_settings': if table == 'prefixes' or table == 'server_settings':
loop.create_task(cache[table].update()) loop.create_task(cache[table].update())
@ -206,9 +209,8 @@ async def get_content(table, key=None):
content = cursor content = cursor
except (IndexError, r.ReqlOpFailedError): except (IndexError, r.ReqlOpFailedError):
content = None content = None
await conn.close() await conn.close()
if table == 'prefixes' or table == 'server_settings':
loop.create_task(cache[table].update())
return content return content
async def filter_content(table: str, r_filter): async def filter_content(table: str, r_filter):
@ -221,9 +223,8 @@ async def filter_content(table: str, r_filter):
content = None content = None
except (IndexError, r.ReqlOpFailedError): except (IndexError, r.ReqlOpFailedError):
content = None content = None
await conn.close() await conn.close()
if table == 'prefixes' or table == 'server_settings':
loop.create_task(cache[table].update())
return content return content