diff --git a/handlers/mainHandler.py b/handlers/mainHandler.py index 4d4e325..7a79bea 100644 --- a/handlers/mainHandler.py +++ b/handlers/mainHandler.py @@ -70,6 +70,7 @@ class handler(SentryMixin, requestHelper.asyncRequestHandler): # Server's token string and request data responseTokenString = "ayy" + responseData = bytes() if requestTokenString is None: # No token, first request. Handle login. diff --git a/helpers/userHelper.py b/helpers/userHelper.py index a6fceba..4b5f5f7 100644 --- a/helpers/userHelper.py +++ b/helpers/userHelper.py @@ -8,21 +8,21 @@ from constants import privileges def getID(username): """ - Get username's user ID + Get username's user ID from userID cache (if cache hit) + or from db (and cache it for other requests) if cache miss - db -- database connection username -- user - return -- user id or False + return -- user id or 0 """ - # Get user ID from db - userID = glob.db.fetch("SELECT id FROM users WHERE username = %s LIMIT 1", [username]) + # Add to cache if needed + if username not in glob.userIDCache: + userID = glob.db.fetch("SELECT id FROM users WHERE username = %s LIMIT 1", [username]) + if userID == None: + return 0 + glob.userIDCache[username] = userID["id"] - # Make sure the query returned something - if userID is None: - return False - - # Return user ID - return userID["id"] + # Get userID from cache + return glob.userIDCache[username] def checkLogin(userID, password): """ diff --git a/objects/glob.py b/objects/glob.py index 3ec6648..efd2191 100644 --- a/objects/glob.py +++ b/objects/glob.py @@ -25,6 +25,7 @@ fLocks = fileLocks.fileLocks() verifiedCache = {} cloudflare = False chatFilters = None +userIDCache = {} debug = False outputRequestTime = False @@ -33,5 +34,6 @@ discord = False gzip = False localize = False sentry = False +irc = False startTime = int(time.time()) diff --git a/objects/osuToken.py b/objects/osuToken.py index fa838b5..1ce5a27 100644 --- a/objects/osuToken.py +++ b/objects/osuToken.py @@ -11,6 +11,7 @@ import threading from helpers import chatHelper as chat class token: + def __init__(self, userID, token_ = None, ip ="", irc = False, timeOffset = 0): """ Create a token object and set userID and token diff --git a/pep.py b/pep.py index 1989b88..a7490e1 100644 --- a/pep.py +++ b/pep.py @@ -1,14 +1,14 @@ """Hello, pep.py here, ex-owner of ripple and prime minister of Ripwot.""" -import sys import os +import sys import threading -# Tornado +import tornado.gen +import tornado.httpserver import tornado.ioloop import tornado.web -import tornado.httpserver -import tornado.gen from gevent import monkey as brit_monkey + brit_monkey.patch_all() # Raven @@ -25,6 +25,7 @@ from helpers import consoleHelper from helpers import databaseHelperNew from helpers import generalFunctions from helpers import logHelper as log +from helpers import userHelper from handlers import mainHandler from handlers import apiIsOnlineHandler @@ -136,9 +137,9 @@ if __name__ == "__main__": consoleHelper.printDone() # Cache user ids - #consoleHelper.printNoNl("> Caching user IDs... ") - #userHelper.cacheUserIDs() - #consoleHelper.printDone() + consoleHelper.printNoNl("> Caching user IDs... ") + userHelper.cacheUserIDs() + consoleHelper.printDone() # Localize warning glob.localize = generalFunctions.stringToBool(glob.conf.config["localize"]["enable"])