Skip to content

Commit 059a9dd

Browse files
author
=
committed
db optimizations
1 parent 1d6fb8c commit 059a9dd

File tree

3 files changed

+111
-12
lines changed

3 files changed

+111
-12
lines changed

auctions/admin.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,31 @@ class UserAdmin(BaseUserAdmin):
237237
inlines = [
238238
UserdataInline,
239239
UserLabelPrefsInline,
240-
AuctionTOSInline, # too much noise, but important to have
241-
InterestInline, # too much noise
240+
# AuctionTOSInline, # too much noise, but important to have
241+
# InterestInline, # too much noise
242242
]
243243
search_fields = (
244244
"first_name",
245245
"last_name",
246-
"userdata__club__abbreviation",
246+
# "userdata__club__abbreviation",
247247
"email",
248248
"username",
249249
)
250250

251+
readonly_fields = [
252+
"last_activity",
253+
"date_joined",
254+
"last_login",
255+
]
256+
257+
def get_queryset(self, request):
258+
return (
259+
super()
260+
.get_queryset(request)
261+
.select_related("userdata__club", "userdata__last_auction_used", "userdata__location")
262+
.prefetch_related("userlabelprefs")
263+
)
264+
251265
def last_activity(self, obj):
252266
return obj.userdata.last_activity
253267

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Generated by Django 5.1.6 on 2025-03-27 15:20
2+
3+
import django.utils.timezone
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
dependencies = [
9+
("auctions", "0179_auctiontos_possible_duplicate"),
10+
]
11+
12+
operations = [
13+
migrations.AlterField(
14+
model_name="auction",
15+
name="use_seller_dash_lot_numbering",
16+
field=models.BooleanField(
17+
blank=True,
18+
default=False,
19+
help_text="Include the seller's bidder number with the lot number. This option is not recommended as users find it confusing.",
20+
),
21+
),
22+
migrations.AlterField(
23+
model_name="auctiontos",
24+
name="is_admin",
25+
field=models.BooleanField(
26+
blank=True,
27+
db_index=True,
28+
default=False,
29+
verbose_name="Grant admin permissions to help run this auction",
30+
),
31+
),
32+
migrations.AlterField(
33+
model_name="lot",
34+
name="active",
35+
field=models.BooleanField(db_index=True, default=True),
36+
),
37+
migrations.AlterField(
38+
model_name="lot",
39+
name="custom_lot_number",
40+
field=models.CharField(
41+
blank=True,
42+
db_index=True,
43+
help_text="You can override the default lot number with this",
44+
max_length=9,
45+
null=True,
46+
verbose_name="Lot number",
47+
),
48+
),
49+
migrations.AlterField(
50+
model_name="lot",
51+
name="latitude",
52+
field=models.FloatField(blank=True, db_index=True, null=True),
53+
),
54+
migrations.AlterField(
55+
model_name="lot",
56+
name="longitude",
57+
field=models.FloatField(blank=True, db_index=True, null=True),
58+
),
59+
migrations.AlterField(
60+
model_name="lot",
61+
name="lot_number_int",
62+
field=models.IntegerField(blank=True, db_index=True, null=True, verbose_name="Lot number"),
63+
),
64+
migrations.AlterField(
65+
model_name="lot",
66+
name="winning_price",
67+
field=models.PositiveIntegerField(blank=True, db_index=True, null=True),
68+
),
69+
migrations.AlterField(
70+
model_name="pageview",
71+
name="date_end",
72+
field=models.DateTimeField(blank=True, db_index=True, default=django.utils.timezone.now, null=True),
73+
),
74+
migrations.AlterField(
75+
model_name="pageview",
76+
name="latitude",
77+
field=models.FloatField(db_index=True, default=0),
78+
),
79+
migrations.AlterField(
80+
model_name="pageview",
81+
name="longitude",
82+
field=models.FloatField(db_index=True, default=0),
83+
),
84+
]

auctions/models.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -1600,6 +1600,7 @@ class AuctionTOS(models.Model):
16001600
default=False,
16011601
verbose_name="Grant admin permissions to help run this auction",
16021602
blank=True,
1603+
db_index=True,
16031604
)
16041605
# yes we are using a string to store a number
16051606
# this is actually important because some day, someone will ask to make the bidder numbers have characters like "1-234" or people's names
@@ -2109,10 +2110,10 @@ class Lot(models.Model):
21092110
# below is the database pk
21102111
lot_number = models.AutoField(primary_key=True)
21112112
# below is an automatically assigned int for use in auctions
2112-
lot_number_int = models.IntegerField(null=True, blank=True, verbose_name="Lot number")
2113+
lot_number_int = models.IntegerField(null=True, blank=True, verbose_name="Lot number", db_index=True)
21132114
# below is an override of the other lot numbers, it was the default for use in auctions until 2025, but now lot_number_int is used instead
21142115
# see https://github.com/iragm/fishauctions/issues/269
2115-
custom_lot_number = models.CharField(max_length=9, blank=True, null=True, verbose_name="Lot number")
2116+
custom_lot_number = models.CharField(max_length=9, blank=True, null=True, verbose_name="Lot number", db_index=True)
21162117
custom_lot_number.help_text = "You can override the default lot number with this"
21172118
lot_name = models.CharField(max_length=40)
21182119
slug = AutoSlugField(populate_from="lot_name", unique=False)
@@ -2188,8 +2189,8 @@ class Lot(models.Model):
21882189
on_delete=models.SET_NULL,
21892190
related_name="auctiontos_winner",
21902191
)
2191-
active = models.BooleanField(default=True)
2192-
winning_price = models.PositiveIntegerField(null=True, blank=True)
2192+
active = models.BooleanField(default=True, db_index=True)
2193+
winning_price = models.PositiveIntegerField(null=True, blank=True, db_index=True)
21932194
refunded = models.BooleanField(default=False)
21942195
refunded.help_text = "Don't charge the winner or pay the seller for this lot."
21952196
banned = models.BooleanField(default=False, verbose_name="Removed", blank=True)
@@ -2243,8 +2244,8 @@ class Lot(models.Model):
22432244
buy_now_used = models.BooleanField(default=False)
22442245

22452246
# Location, populated from userdata. This is needed to prevent users from changing their address after posting a lot
2246-
latitude = models.FloatField(blank=True, null=True)
2247-
longitude = models.FloatField(blank=True, null=True)
2247+
latitude = models.FloatField(blank=True, null=True, db_index=True)
2248+
longitude = models.FloatField(blank=True, null=True, db_index=True)
22482249
address = models.CharField(max_length=500, blank=True, null=True)
22492250

22502251
# Payment and shipping options, populated from last submitted lot
@@ -3701,7 +3702,7 @@ class PageView(models.Model):
37013702
lot_number = models.ForeignKey(Lot, null=True, blank=True, on_delete=models.CASCADE)
37023703
lot_number.help_text = "Only filled out when a user views a specific lot's page"
37033704
date_start = models.DateTimeField(auto_now_add=True, db_index=True)
3704-
date_end = models.DateTimeField(null=True, blank=True, default=timezone.now)
3705+
date_end = models.DateTimeField(null=True, blank=True, default=timezone.now, db_index=True)
37053706
total_time = models.PositiveIntegerField(default=0)
37063707
total_time.help_text = "The total time in seconds the user has spent on the lot page"
37073708
source = models.CharField(max_length=200, blank=True, null=True, default="")
@@ -3712,8 +3713,8 @@ class PageView(models.Model):
37123713
session_id = models.CharField(max_length=600, blank=True, null=True, db_index=True)
37133714
notification_sent = models.BooleanField(default=False)
37143715
duplicate_check_completed = models.BooleanField(default=False)
3715-
latitude = models.FloatField(default=0)
3716-
longitude = models.FloatField(default=0)
3716+
latitude = models.FloatField(default=0, db_index=True)
3717+
longitude = models.FloatField(default=0, db_index=True)
37173718
ip_address = models.CharField(max_length=100, blank=True, null=True)
37183719
user_agent = models.CharField(max_length=200, blank=True, null=True)
37193720
platform = models.CharField(max_length=200, default="", blank=True, null=True)

0 commit comments

Comments
 (0)