testing on identify

This commit is contained in:
Jeremy Zhang 2019-01-01 19:32:28 +00:00
parent 510f801f79
commit 0bafccc044
3 changed files with 7 additions and 8 deletions

View File

@ -8,13 +8,11 @@ import json
from titanembeds.decorators import timeit from titanembeds.decorators import timeit
class Gateway(Namespace): class Gateway(Namespace):
@timeit
def teardown_db_session(self): def teardown_db_session(self):
time.sleep(0) time.sleep(0)
db.session.commit() db.session.commit()
db.session.remove() db.session.remove()
@timeit
def on_connect(self): def on_connect(self):
emit('hello') emit('hello')
@ -52,7 +50,6 @@ class Gateway(Namespace):
emit("identified") emit("identified")
self.teardown_db_session() self.teardown_db_session()
@timeit
def on_disconnect(self): def on_disconnect(self):
time.sleep(0) time.sleep(0)
if "user_keys" not in session: if "user_keys" not in session:
@ -85,7 +82,6 @@ class Gateway(Namespace):
discord_api.delete_webhook(webhook["id"], webhook["token"]) discord_api.delete_webhook(webhook["id"], webhook["token"])
self.teardown_db_session() self.teardown_db_session()
@timeit
def on_heartbeat(self, data): def on_heartbeat(self, data):
time.sleep(0) time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
@ -118,7 +114,6 @@ class Gateway(Namespace):
return return
self.teardown_db_session() self.teardown_db_session()
@timeit
def on_channel_list(self, data): def on_channel_list(self, data):
time.sleep(0) time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
@ -140,7 +135,6 @@ class Gateway(Namespace):
emit("channel_list", channels) emit("channel_list", channels)
self.teardown_db_session() self.teardown_db_session()
@timeit
def on_current_user_info(self, data): def on_current_user_info(self, data):
time.sleep(0) time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:
@ -159,7 +153,6 @@ class Gateway(Namespace):
emit("current_user_info", usr) emit("current_user_info", usr)
self.teardown_db_session() self.teardown_db_session()
@timeit
def get_user_color(self, guild_id, user_id): def get_user_color(self, guild_id, user_id):
color = None color = None
member = redisqueue.get_guild_member(guild_id, user_id) member = redisqueue.get_guild_member(guild_id, user_id)
@ -188,7 +181,6 @@ class Gateway(Namespace):
color = "0" + color color = "0" + color
return color return color
@timeit
def on_lookup_user_info(self, data): def on_lookup_user_info(self, data):
time.sleep(0) time.sleep(0)
if "socket_guild_id" not in session: if "socket_guild_id" not in session:

View File

@ -1,6 +1,7 @@
from titanembeds.utils import redis_store from titanembeds.utils import redis_store
import json import json
import time import time
from titanembeds.decorators import timeit
class RedisQueue: class RedisQueue:
def __init__(self): def __init__(self):
@ -93,6 +94,7 @@ class RedisQueue:
sorted_msgs = sorted(msgs, key=lambda k: k['id'], reverse=True) sorted_msgs = sorted(msgs, key=lambda k: k['id'], reverse=True)
return sorted_msgs[:50] # only return last 50 messages in cache please return sorted_msgs[:50] # only return last 50 messages in cache please
@timeit
def get_guild_member(self, guild_id, user_id): def get_guild_member(self, guild_id, user_id):
key = "/guilds/{}/members/{}".format(guild_id, user_id) key = "/guilds/{}/members/{}".format(guild_id, user_id)
q = self.get(key, "get_guild_member", {"guild_id": guild_id, "user_id": user_id}) q = self.get(key, "get_guild_member", {"guild_id": guild_id, "user_id": user_id})

View File

@ -13,6 +13,7 @@ import string
import hashlib import hashlib
import time import time
import json import json
from titanembeds.decorators import timeit
redis_store = FlaskRedis(charset="utf-8", decode_responses=True) redis_store = FlaskRedis(charset="utf-8", decode_responses=True)
@ -79,6 +80,7 @@ def check_guild_existance(guild_id):
else: else:
return True return True
@timeit
def guild_accepts_visitors(guild_id): def guild_accepts_visitors(guild_id):
dbGuild = Guilds.query.filter_by(guild_id=guild_id).first() dbGuild = Guilds.query.filter_by(guild_id=guild_id).first()
return dbGuild.visitor_view return dbGuild.visitor_view
@ -191,6 +193,7 @@ def get_online_embed_user_keys(guild_id="*", user_type=None):
usrs[utype].append(client_key) usrs[utype].append(client_key)
return usrs return usrs
@timeit
def check_user_in_guild(guild_id): def check_user_in_guild(guild_id):
if user_unauthenticated(): if user_unauthenticated():
return guild_id in session.get("user_keys", {}) return guild_id in session.get("user_keys", {})
@ -207,6 +210,7 @@ def get_member_roles(guild_id, user_id):
role_converted.append(str(role)) role_converted.append(str(role))
return role_converted return role_converted
@timeit
def get_guild_channels(guild_id, force_everyone=False, forced_role=0): def get_guild_channels(guild_id, force_everyone=False, forced_role=0):
if user_unauthenticated() or force_everyone: if user_unauthenticated() or force_everyone:
member_roles = [guild_id] #equivilant to @everyone role member_roles = [guild_id] #equivilant to @everyone role
@ -315,6 +319,7 @@ def get_channel_permission(channel, guild_id, guild_owner, guild_roles, member_r
result["attach_files"] = False result["attach_files"] = False
return result return result
@timeit
def get_forced_role(guild_id): def get_forced_role(guild_id):
dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first() dbguild = db.session.query(Guilds).filter(Guilds.guild_id == guild_id).first()
if not session.get("unauthenticated", True): if not session.get("unauthenticated", True):