mirror of
https://git.wownero.com/wownero/tippero.git
synced 2024-08-15 00:33:14 +00:00
Cache tipbot balance for a time to avoid bottleneck
This commit is contained in:
parent
69582695f6
commit
ee7fa9172b
2 changed files with 12 additions and 0 deletions
|
@ -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"]
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue