feat: Try some more optimizations
This commit is contained in:
117
main.py
117
main.py
@@ -273,74 +273,85 @@ def auctions():
|
|||||||
if not account:
|
if not account:
|
||||||
return redirect("/logout")
|
return redirect("/logout")
|
||||||
|
|
||||||
# Get sort parameters with defaults
|
|
||||||
sort = request.args.get("sort", "time").lower()
|
|
||||||
direction = request.args.get("direction")
|
|
||||||
if direction is None:
|
|
||||||
direction = "⬆" if sort == "time" else "⬇"
|
|
||||||
|
|
||||||
reverse = (direction == "⬆")
|
|
||||||
|
|
||||||
# Initialize sort indicators with a more efficient approach
|
|
||||||
sort_indicators = {
|
|
||||||
"price": ["", "⬇"],
|
|
||||||
"state": ["", "⬇"],
|
|
||||||
"domain": ["", "⬇"],
|
|
||||||
"time": ["", "⬇"]
|
|
||||||
}
|
|
||||||
# Set the current sort column's indicators
|
|
||||||
sort_indicators[sort][0] = direction
|
|
||||||
sort_indicators[sort][1] = reverseDirection(direction)
|
|
||||||
|
|
||||||
# Efficiently retrieve data
|
|
||||||
bids = account_module.getBids(account)
|
bids = account_module.getBids(account)
|
||||||
domains = account_module.getDomains(account, False)
|
domains = account_module.getDomains(account,False)
|
||||||
|
|
||||||
|
# Sort
|
||||||
|
sort = request.args.get("sort")
|
||||||
|
if sort == None:
|
||||||
|
sort = "time"
|
||||||
|
sort = sort.lower()
|
||||||
|
sort_price = ""
|
||||||
|
sort_price_next = "⬇"
|
||||||
|
sort_state = ""
|
||||||
|
sort_state_next = "⬇"
|
||||||
|
sort_domain = ""
|
||||||
|
sort_domain_next = "⬇"
|
||||||
|
sort_time = ""
|
||||||
|
sort_time_next = "⬇"
|
||||||
|
reverse = False
|
||||||
|
|
||||||
|
direction = request.args.get("direction")
|
||||||
|
if direction == None:
|
||||||
|
if sort == "time":
|
||||||
|
direction = "⬆"
|
||||||
|
else:
|
||||||
|
direction = "⬇"
|
||||||
|
|
||||||
|
if direction == "⬆":
|
||||||
|
reverse = True
|
||||||
|
|
||||||
# Determine if sorting by domains and apply appropriate sort
|
|
||||||
sortbyDomain = False
|
sortbyDomain = False
|
||||||
|
|
||||||
if sort == "price":
|
if sort == "price":
|
||||||
bids = sorted(bids, key=lambda k: k['value'], reverse=reverse)
|
# Sort by price
|
||||||
|
bids = sorted(bids, key=lambda k: k['value'],reverse=reverse)
|
||||||
|
sort_price = direction
|
||||||
|
sort_price_next = reverseDirection(direction)
|
||||||
elif sort == "state":
|
elif sort == "state":
|
||||||
domains = sorted(domains, key=lambda k: k['state'], reverse=reverse)
|
sort_state = direction
|
||||||
|
sort_state_next = reverseDirection(direction)
|
||||||
|
domains = sorted(domains, key=lambda k: k['state'],reverse=reverse)
|
||||||
sortbyDomain = True
|
sortbyDomain = True
|
||||||
elif sort == "time":
|
elif sort == "time":
|
||||||
# Handle older HSD versions that don't have height in bids
|
sort_time = direction
|
||||||
if bids and bids[0]['height'] == 0:
|
sort_time_next = reverseDirection(direction)
|
||||||
domains = sorted(domains, key=lambda k: k['height'], reverse=reverse)
|
|
||||||
|
# If older HSD version sort by domain height
|
||||||
|
if bids[0]['height'] == 0:
|
||||||
|
domains = sorted(domains, key=lambda k: k['height'],reverse=reverse)
|
||||||
sortbyDomain = True
|
sortbyDomain = True
|
||||||
else:
|
else:
|
||||||
bids = sorted(bids, key=lambda k: k['height'], reverse=reverse)
|
bids = sorted(bids, key=lambda k: k['height'],reverse=reverse)
|
||||||
else: # Default to domain name sorting
|
else:
|
||||||
bids = sorted(bids, key=lambda k: k['name'], reverse=reverse)
|
# Sort by domain
|
||||||
|
bids = sorted(bids, key=lambda k: k['name'],reverse=reverse)
|
||||||
|
sort_domain = direction
|
||||||
|
sort_domain_next = reverseDirection(direction)
|
||||||
|
|
||||||
# Get outbids only if explicitly requested
|
# Check if outbids set to true
|
||||||
outbids = []
|
outbids = request.args.get("outbids")
|
||||||
if request.args.get("outbids", "").lower() == "true":
|
if outbids is not None and outbids.lower() == "true":
|
||||||
|
# Get outbid domains
|
||||||
outbids = account_module.getPossibleOutbids(account)
|
outbids = account_module.getPossibleOutbids(account)
|
||||||
|
else:
|
||||||
|
outbids = []
|
||||||
|
|
||||||
# Generate HTML just once
|
bidsHtml = render.bidDomains(bids,domains,sortbyDomain,outbids)
|
||||||
bidsHtml = render.bidDomains(bids, domains, sortbyDomain, outbids)
|
plugins = ""
|
||||||
|
message = ''
|
||||||
|
if 'message' in request.args:
|
||||||
|
message = request.args.get("message")
|
||||||
|
return render_template("auctions.html", account=account, domains=bidsHtml,
|
||||||
|
domainsMobile=bidsHtml, plugins=plugins,
|
||||||
|
domain_count=bidsHtml,sort_price=sort_price,
|
||||||
|
sort_state=sort_state,sort_domain=sort_domain,
|
||||||
|
sort_price_next=sort_price_next,
|
||||||
|
sort_state_next=sort_state_next,sort_domain_next=sort_domain_next,
|
||||||
|
bids=len(bids),message=message,
|
||||||
|
sort_time=sort_time,sort_time_next=sort_time_next)
|
||||||
|
|
||||||
# Get message if present
|
|
||||||
message = request.args.get("message", "")
|
|
||||||
|
|
||||||
return render_template("auctions.html", account=account,
|
|
||||||
domains=bidsHtml,
|
|
||||||
domainsMobile=bidsHtml,
|
|
||||||
plugins="",
|
|
||||||
domain_count=bidsHtml,
|
|
||||||
sort_price=sort_indicators["price"][0],
|
|
||||||
sort_state=sort_indicators["state"][0],
|
|
||||||
sort_domain=sort_indicators["domain"][0],
|
|
||||||
sort_time=sort_indicators["time"][0],
|
|
||||||
sort_price_next=sort_indicators["price"][1],
|
|
||||||
sort_state_next=sort_indicators["state"][1],
|
|
||||||
sort_domain_next=sort_indicators["domain"][1],
|
|
||||||
sort_time_next=sort_indicators["time"][1],
|
|
||||||
bids=len(bids),
|
|
||||||
message=message)
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
#region All Auctions
|
#region All Auctions
|
||||||
@app.route('/reveal')
|
@app.route('/reveal')
|
||||||
|
|||||||
72
render.py
72
render.py
@@ -336,55 +336,12 @@ def bids(bids,reveals):
|
|||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
def bidDomains(bids, domains, sortbyDomains=False, outbids=[]):
|
def bidDomains(bids,domains, sortbyDomains=False, outbids=[]):
|
||||||
html = ''
|
html = ''
|
||||||
|
|
||||||
# Create lookup dictionaries for O(1) lookups instead of O(n) searches
|
|
||||||
domain_lookup = {d['name']: d for d in domains}
|
|
||||||
bid_lookup = {}
|
|
||||||
for bid in bids:
|
|
||||||
if bid['name'] not in bid_lookup or bid['value'] > bid_lookup[bid['name']]['value']:
|
|
||||||
bid_lookup[bid['name']] = bid
|
|
||||||
|
|
||||||
if not sortbyDomains:
|
if not sortbyDomains:
|
||||||
# Process by bids first
|
|
||||||
for bid in bids:
|
for bid in bids:
|
||||||
domain_name = bid['name']
|
|
||||||
if domain_name not in domain_lookup:
|
|
||||||
continue
|
|
||||||
|
|
||||||
domain = domain_lookup[domain_name]
|
|
||||||
|
|
||||||
lockup = bid['lockup']
|
|
||||||
lockup = lockup / 1000000
|
|
||||||
bidValue = bid['value'] / 1000000
|
|
||||||
blind = lockup - bidValue
|
|
||||||
|
|
||||||
if blind > 0:
|
|
||||||
bidDisplay = f'<b>{bidValue:,.2f}</b> (+{blind:,.2f}) HNS'
|
|
||||||
else:
|
|
||||||
bidDisplay = f'<b>{bidValue:,.2f}</b> HNS'
|
|
||||||
|
|
||||||
html += "<tr>"
|
|
||||||
|
|
||||||
# Efficiently check if domain is in outbids list
|
|
||||||
is_outbid = domain_name in outbids
|
|
||||||
td_style = " style='background-color: red;'" if is_outbid else ""
|
|
||||||
|
|
||||||
html += f"<td{td_style}><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain_name}'>{renderDomain(domain_name)}</a></td>"
|
|
||||||
html += f"<td>{domain['state']}</td>"
|
|
||||||
html += f"<td style='white-space: nowrap;'>{bidDisplay}</td>"
|
|
||||||
html += f"<td class='hide-mobile'>{bid['height']:,}</td>"
|
|
||||||
html += "</tr>"
|
|
||||||
else:
|
|
||||||
# Process by domains first (for state sorting)
|
|
||||||
for domain in domains:
|
for domain in domains:
|
||||||
domain_name = domain['name']
|
if bid['name'] == domain['name']:
|
||||||
if domain_name not in bid_lookup:
|
|
||||||
continue
|
|
||||||
|
|
||||||
bid = bid_lookup[domain_name]
|
|
||||||
|
|
||||||
lockup = bid['lockup']
|
lockup = bid['lockup']
|
||||||
lockup = lockup / 1000000
|
lockup = lockup / 1000000
|
||||||
bidValue = bid['value'] / 1000000
|
bidValue = bid['value'] / 1000000
|
||||||
@@ -396,17 +353,30 @@ def bidDomains(bids, domains, sortbyDomains=False, outbids=[]):
|
|||||||
bidDisplay = f'<b>{bidValue:,.2f}</b> HNS'
|
bidDisplay = f'<b>{bidValue:,.2f}</b> HNS'
|
||||||
|
|
||||||
html += "<tr>"
|
html += "<tr>"
|
||||||
|
if domain['name'] in outbids:
|
||||||
# Efficiently check if domain is in outbids list
|
html += f"<td style='background-color: red;'><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
||||||
is_outbid = domain_name in outbids
|
else:
|
||||||
td_style = " style='background-color: red;'" if is_outbid else ""
|
html += f"<td><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
||||||
|
|
||||||
html += f"<td{td_style}><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain_name}'>{renderDomain(domain_name)}</a></td>"
|
|
||||||
html += f"<td>{domain['state']}</td>"
|
html += f"<td>{domain['state']}</td>"
|
||||||
html += f"<td style='white-space: nowrap;'>{bidDisplay}</td>"
|
html += f"<td style='white-space: nowrap;'>{bidDisplay}</td>"
|
||||||
html += f"<td class='hide-mobile'>{bid['height']:,}</td>"
|
html += f"<td class='hide-mobile'>{bid['height']:,}</td>"
|
||||||
html += "</tr>"
|
html += "</tr>"
|
||||||
|
else:
|
||||||
|
for domain in domains:
|
||||||
|
for bid in bids:
|
||||||
|
if bid['name'] == domain['name']:
|
||||||
|
lockup = bid['lockup']
|
||||||
|
lockup = lockup / 1000000
|
||||||
|
bidValue = bid['value'] / 1000000
|
||||||
|
blind = lockup - bidValue
|
||||||
|
|
||||||
|
bidDisplay = f'<b>{bidValue:,.2f} HNS</b> + {blind:,.2f} HNS blind'
|
||||||
|
html += "<tr>"
|
||||||
|
html += f"<td><a class='text-decoration-none' style='color: var(--bs-table-color-state, var(--bs-table-color-type, var(--bs-table-color)));' href='/auction/{domain['name']}'>{renderDomain(domain['name'])}</a></td>"
|
||||||
|
html += f"<td>{domain['state']}</td>"
|
||||||
|
html += f"<td>{bidDisplay}</td>"
|
||||||
|
html += f"<td class='hide-mobile'>{bid['height']:,}</td>"
|
||||||
|
html += "</tr>"
|
||||||
return html
|
return html
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user