Cache tipbot balance for a time to avoid bottleneck

This commit is contained in:
moneromooo 2015-01-25 21:09:56 +00:00
parent 69582695f6
commit ee7fa9172b
2 changed files with 12 additions and 0 deletions

View File

@ -35,6 +35,7 @@ min_withdraw_amount = None # None defaults to the withdrawal fee
withdrawal_mixin=0
disable_withdraw_on_error = True
payment_confirmations = 6
tipbot_balance_cache_time = 35 # seconds
admins = ["freenode:moneromooo", "freenode:moneromoo"]

View File

@ -13,12 +13,16 @@ import redis
import hashlib
import json
import httplib
import time
import tipbot.config as config
import tipbot.coinspecs as coinspecs
from tipbot.log import log_error, log_warn, log_info, log_log
from tipbot.redisdb import *
networks=[]
cached_tipbot_balance=None
cached_tipbot_unlocked_balance=None
cached_tipbot_balance_timestamp=None
def GetPassword():
try:
@ -185,6 +189,10 @@ def SendDaemonHTMLCommand(method):
return SendHTMLCommand(config.daemon_host,config.daemon_port,method)
def RetrieveTipbotBalance():
global cached_tipbot_balance, cached_tipbot_unlocked_balance, cached_tipbot_balance_timestamp
if cached_tipbot_balance_timestamp and time.time()-cached_tipbot_balance_timestamp < config.tipbot_balance_cache_time:
return cached_tipbot_balance, cached_tipbot_unlocked_balance
j = SendWalletJSONRPCCommand("getbalance",None)
if not "result" in j:
log_error('RetrieveTipbotBalance: result not found in reply')
@ -208,6 +216,9 @@ def RetrieveTipbotBalance():
log_error('RetrieveTipbotBalance: Negative pending balance! balance %s, unlocked %s' % (str(balance),str(unlocked_balance)))
raise RuntimeError("")
return
cached_tipbot_balance_timestamp=time.time()
cached_tipbot_balance=balance
cached_tipbot_unlocked_balance=unlocked_balance
return balance, unlocked_balance
def RetrieveBalance(link):