.BANCHO. Add userID cache
This commit is contained in:
parent
cf60c167b6
commit
9ee2e5d7ff
|
@ -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.
|
||||
|
|
|
@ -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):
|
||||
"""
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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
|
||||
|
|
15
pep.py
15
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"])
|
||||
|
|
Loading…
Reference in New Issue
Block a user