parent
1dcd750fea
commit
cbb3d0ac02
8 changed files with 138 additions and 40 deletions
@ -0,0 +1,54 @@ |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
# Copyright (c) 2023 The BSX Developers |
||||
# Distributed under the MIT software license, see the accompanying |
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. |
||||
|
||||
from .db import ( |
||||
Concepts, |
||||
) |
||||
|
||||
|
||||
def remove_expired_data(self): |
||||
self.log.warning('Removing expired data') |
||||
now: int = self.getTime() |
||||
try: |
||||
session = self.openSession() |
||||
|
||||
active_bids_insert = self.activeBidsQueryStr(now, '', 'b2') |
||||
query_str = f''' |
||||
SELECT o.offer_id FROM offers o |
||||
WHERE o.expire_at <= :now AND 0 = (SELECT COUNT(*) FROM bids b2 WHERE b2.offer_id = o.offer_id AND {active_bids_insert}) |
||||
''' |
||||
num_offers = 0 |
||||
num_bids = 0 |
||||
offer_rows = session.execute(query_str, {'now': now}) |
||||
for offer_row in offer_rows: |
||||
num_offers += 1 |
||||
bid_rows = session.execute('SELECT bids.bid_id FROM bids WHERE bids.offer_id = :offer_id', {'offer_id': offer_row[0]}) |
||||
for bid_row in bid_rows: |
||||
num_bids += 1 |
||||
session.execute('DELETE FROM transactions WHERE transactions.bid_id = :bid_id', {'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM eventlog WHERE eventlog.linked_type = :type_ind AND eventlog.linked_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM automationlinks WHERE automationlinks.linked_type = :type_ind AND automationlinks.linked_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM prefunded_transactions WHERE prefunded_transactions.linked_type = :type_ind AND prefunded_transactions.linked_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM history WHERE history.concept_type = :type_ind AND history.concept_id = :bid_id', {'type_ind': int(Concepts.BID), 'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM xmr_swaps WHERE xmr_swaps.bid_id = :bid_id', {'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM actions WHERE actions.linked_id = :bid_id', {'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM addresspool WHERE addresspool.bid_id = :bid_id', {'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM xmr_split_data WHERE xmr_split_data.bid_id = :bid_id', {'bid_id': bid_row[0]}) |
||||
session.execute('DELETE FROM bids WHERE bids.bid_id = :bid_id', {'bid_id': bid_row[0]}) |
||||
|
||||
session.execute('DELETE FROM eventlog WHERE eventlog.linked_type = :type_ind AND eventlog.linked_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM automationlinks WHERE automationlinks.linked_type = :type_ind AND automationlinks.linked_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM prefunded_transactions WHERE prefunded_transactions.linked_type = :type_ind AND prefunded_transactions.linked_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM history WHERE history.concept_type = :type_ind AND history.concept_id = :offer_id', {'type_ind': int(Concepts.OFFER), 'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM xmr_offers WHERE xmr_offers.offer_id = :offer_id', {'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM sentoffers WHERE sentoffers.offer_id = :offer_id', {'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM actions WHERE actions.linked_id = :offer_id', {'offer_id': offer_row[0]}) |
||||
session.execute('DELETE FROM offers WHERE offers.offer_id = :offer_id', {'offer_id': offer_row[0]}) |
||||
|
||||
self.log.warning(f'Removed data for {num_offers} expired offers and {num_bids} bids.') |
||||
|
||||
finally: |
||||
self.closeSession(session) |
@ -0,0 +1,54 @@ |
||||
# -*- coding: utf-8 -*- |
||||
|
||||
# Copyright (c) 2023 The BSX Developers |
||||
# Distributed under the MIT software license, see the accompanying |
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. |
||||
|
||||
import traceback |
||||
from .util import ( |
||||
have_data_entry, |
||||
) |
||||
from basicswap.chainparams import ( |
||||
Coins, |
||||
) |
||||
from basicswap.db_util import ( |
||||
remove_expired_data, |
||||
) |
||||
|
||||
|
||||
def page_debug(self, url_split, post_string): |
||||
server = self.server |
||||
swap_client = server.swap_client |
||||
swap_client.checkSystemStatus() |
||||
summary = swap_client.getSummary() |
||||
|
||||
result = None |
||||
messages = [] |
||||
err_messages = [] |
||||
form_data = self.checkForm(post_string, 'wallets', err_messages) |
||||
if form_data: |
||||
if have_data_entry(form_data, 'reinit_xmr'): |
||||
try: |
||||
swap_client.initialiseWallet(Coins.XMR) |
||||
messages.append('Done.') |
||||
except Exception as e: |
||||
err_messages.append('Failed.') |
||||
|
||||
if have_data_entry(form_data, 'remove_expired'): |
||||
try: |
||||
remove_expired_data(swap_client) |
||||
messages.append('Done.') |
||||
except Exception as e: |
||||
if swap_client.debug is True: |
||||
swap_client.log.error(traceback.format_exc()) |
||||
else: |
||||
swap_client.log.error(f'remove_expired_data: {e}') |
||||
err_messages.append('Failed.') |
||||
|
||||
template = server.env.get_template('debug.html') |
||||
return self.render_template(template, { |
||||
'messages': messages, |
||||
'err_messages': err_messages, |
||||
'result': result, |
||||
'summary': summary, |
||||
}) |
Loading…
Reference in new issue