Archive old reference IDs

This commit is contained in:
Mark Veidemanis 2021-12-29 15:03:47 +00:00
parent b1fa6182ef
commit be46f79ef7
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
2 changed files with 23 additions and 1 deletions

View File

@ -99,6 +99,7 @@ class Agora(object):
for ref in list(self.last_dash): # We're removing from the list on the fly for ref in list(self.last_dash): # We're removing from the list on the fly
if ref not in current_trades: if ref not in current_trades:
self.last_dash.remove(ref) self.last_dash.remove(ref)
self.tx.cleanup(current_trades)
return dash_tmp return dash_tmp
def dashboard_release_urls(self): def dashboard_release_urls(self):

View File

@ -163,6 +163,19 @@ class Transactions(object):
references.append(r.get(key)) references.append(r.get(key))
return convert(references) return convert(references)
def get_ref_map(self):
"""
Get all reference IDs for trades.
:return: dict of references keyed by TXID
:rtype: dict
"""
references = {}
ref_keys = r.keys("trade.*.reference")
for key in ref_keys:
tx = convert(key).split(".")[1]
references[tx] = r.get(key)
return convert(references)
def get_ref(self, reference): def get_ref(self, reference):
""" """
Get a reference ID for a single trade. Get a reference ID for a single trade.
@ -178,8 +191,16 @@ class Transactions(object):
""" """
Delete a given reference from the Redis database. Delete a given reference from the Redis database.
""" """
tx = self.ref_to_tx(reference)
r.delete(f"trade.{reference}") r.delete(f"trade.{reference}")
r.delete(f"trade.{reference}.reference") r.delete(f"trade.{tx}.reference")
def cleanup(self, references):
for tx, reference in self.get_ref_map().items():
if reference not in references:
self.log.info("Archiving trade reference: {reference} / TX: {tx}", reference=reference, tx=tx)
r.rename(f"trade.{tx}.reference", f"archive.trade.{tx}.reference")
r.rename(f"trade.{reference}", f"archive.trade.{reference}")
def del_tx(self, txid): def del_tx(self, txid):
pass pass