Remove django-auto-prefetch

This commit is contained in:
2025-05-01 02:47:09 +02:00
parent d7b31e1d42
commit 73f1870431
4 changed files with 29 additions and 108 deletions

View File

@ -16,6 +16,7 @@
"createcachetable", "createcachetable",
"createsuperuser", "createsuperuser",
"djade", "djade",
"djlint",
"docstrings", "docstrings",
"dotenv", "dotenv",
"dropcampaign", "dropcampaign",
@ -43,6 +44,7 @@
"psycopg", "psycopg",
"PUID", "PUID",
"pydocstyle", "pydocstyle",
"pytest",
"pyupgrade", "pyupgrade",
"requirepass", "requirepass",
"rewardcampaign", "rewardcampaign",

View File

@ -1,11 +1,9 @@
# Generated by Django 5.2 on 2025-05-01 00:02 # Generated by Django 5.2 on 2025-05-01 00:45
from __future__ import annotations from __future__ import annotations
import auto_prefetch
import django.contrib.auth.models import django.contrib.auth.models
import django.contrib.auth.validators import django.contrib.auth.validators
import django.db.models.deletion import django.db.models.deletion
import django.db.models.manager
import django.utils.timezone import django.utils.timezone
from django.db import migrations, models from django.db import migrations, models
@ -39,13 +37,7 @@ class Migration(migrations.Migration):
], ],
options={ options={
"ordering": ["display_name"], "ordering": ["display_name"],
"abstract": False,
"base_manager_name": "prefetch_manager",
}, },
managers=[
("objects", django.db.models.manager.Manager()),
("prefetch_manager", django.db.models.manager.Manager()),
],
), ),
migrations.CreateModel( migrations.CreateModel(
name="Organization", name="Organization",
@ -65,13 +57,7 @@ class Migration(migrations.Migration):
], ],
options={ options={
"ordering": ["name"], "ordering": ["name"],
"abstract": False,
"base_manager_name": "prefetch_manager",
}, },
managers=[
("objects", django.db.models.manager.Manager()),
("prefetch_manager", django.db.models.manager.Manager()),
],
), ),
migrations.CreateModel( migrations.CreateModel(
name="ScrapedJson", name="ScrapedJson",
@ -84,13 +70,7 @@ class Migration(migrations.Migration):
], ],
options={ options={
"ordering": ["-created_at"], "ordering": ["-created_at"],
"abstract": False,
"base_manager_name": "prefetch_manager",
}, },
managers=[
("objects", django.db.models.manager.Manager()),
("prefetch_manager", django.db.models.manager.Manager()),
],
), ),
migrations.CreateModel( migrations.CreateModel(
name="User", name="User",
@ -203,7 +183,7 @@ class Migration(migrations.Migration):
), ),
( (
"game", "game",
auto_prefetch.ForeignKey( models.ForeignKey(
help_text="The game associated with this campaign", help_text="The game associated with this campaign",
null=True, null=True,
on_delete=django.db.models.deletion.SET_NULL, on_delete=django.db.models.deletion.SET_NULL,
@ -213,7 +193,7 @@ class Migration(migrations.Migration):
), ),
( (
"owner", "owner",
auto_prefetch.ForeignKey( models.ForeignKey(
help_text="The organization running this campaign", help_text="The organization running this campaign",
null=True, null=True,
on_delete=django.db.models.deletion.SET_NULL, on_delete=django.db.models.deletion.SET_NULL,
@ -224,13 +204,7 @@ class Migration(migrations.Migration):
], ],
options={ options={
"ordering": ["end_at"], "ordering": ["end_at"],
"abstract": False,
"base_manager_name": "prefetch_manager",
}, },
managers=[
("objects", django.db.models.manager.Manager()),
("prefetch_manager", django.db.models.manager.Manager()),
],
), ),
migrations.CreateModel( migrations.CreateModel(
name="Benefit", name="Benefit",
@ -263,7 +237,7 @@ class Migration(migrations.Migration):
("modified_at", models.DateTimeField(auto_now=True)), ("modified_at", models.DateTimeField(auto_now=True)),
( (
"game", "game",
auto_prefetch.ForeignKey( models.ForeignKey(
null=True, null=True,
on_delete=django.db.models.deletion.SET_NULL, on_delete=django.db.models.deletion.SET_NULL,
related_name="benefits", related_name="benefits",
@ -272,7 +246,7 @@ class Migration(migrations.Migration):
), ),
( (
"owner_organization", "owner_organization",
auto_prefetch.ForeignKey( models.ForeignKey(
null=True, null=True,
on_delete=django.db.models.deletion.SET_NULL, on_delete=django.db.models.deletion.SET_NULL,
related_name="benefits", related_name="benefits",
@ -282,13 +256,7 @@ class Migration(migrations.Migration):
], ],
options={ options={
"ordering": ["-twitch_created_at"], "ordering": ["-twitch_created_at"],
"abstract": False,
"base_manager_name": "prefetch_manager",
}, },
managers=[
("objects", django.db.models.manager.Manager()),
("prefetch_manager", django.db.models.manager.Manager()),
],
), ),
migrations.CreateModel( migrations.CreateModel(
name="TimeBasedDrop", name="TimeBasedDrop",
@ -329,7 +297,7 @@ class Migration(migrations.Migration):
), ),
( (
"campaign", "campaign",
auto_prefetch.ForeignKey( models.ForeignKey(
help_text="The campaign this drop belongs to", help_text="The campaign this drop belongs to",
on_delete=django.db.models.deletion.CASCADE, on_delete=django.db.models.deletion.CASCADE,
related_name="time_based_drops", related_name="time_based_drops",
@ -339,12 +307,6 @@ class Migration(migrations.Migration):
], ],
options={ options={
"ordering": ["required_minutes_watched"], "ordering": ["required_minutes_watched"],
"abstract": False,
"base_manager_name": "prefetch_manager",
}, },
managers=[
("objects", django.db.models.manager.Manager()),
("prefetch_manager", django.db.models.manager.Manager()),
],
), ),
] ]

View File

@ -3,7 +3,6 @@ from __future__ import annotations
import logging import logging
from typing import ClassVar from typing import ClassVar
import auto_prefetch
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.db import models from django.db import models
@ -21,7 +20,7 @@ class User(AbstractUser):
return self.username return self.username
class ScrapedJson(auto_prefetch.Model): class ScrapedJson(models.Model):
"""The JSON data from the Twitch API. """The JSON data from the Twitch API.
This data is from https://github.com/TheLovinator1/TwitchDropsMiner. This data is from https://github.com/TheLovinator1/TwitchDropsMiner.
@ -32,7 +31,7 @@ class ScrapedJson(auto_prefetch.Model):
modified_at = models.DateTimeField(auto_now=True) modified_at = models.DateTimeField(auto_now=True)
imported_at = models.DateTimeField(null=True) imported_at = models.DateTimeField(null=True)
class Meta(auto_prefetch.Model.Meta): class Meta:
ordering: ClassVar[list[str]] = ["-created_at"] ordering: ClassVar[list[str]] = ["-created_at"]
def __str__(self) -> str: def __str__(self) -> str:
@ -40,7 +39,7 @@ class ScrapedJson(auto_prefetch.Model):
return f"{'' if self.imported_at else 'Not imported - '}{self.created_at}" return f"{'' if self.imported_at else 'Not imported - '}{self.created_at}"
class Organization(auto_prefetch.Model): class Organization(models.Model):
"""Represents the owner/organization of a Drop Campaign.""" """Represents the owner/organization of a Drop Campaign."""
org_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the owner.") org_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the owner.")
@ -49,7 +48,7 @@ class Organization(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True) modified_at = models.DateTimeField(auto_now=True)
class Meta(auto_prefetch.Model.Meta): class Meta:
ordering: ClassVar[list[str]] = ["name"] ordering: ClassVar[list[str]] = ["name"]
def __str__(self) -> str: def __str__(self) -> str:
@ -57,7 +56,7 @@ class Organization(auto_prefetch.Model):
return f"{self.name or self.org_id} - {self.created_at}" return f"{self.name or self.org_id} - {self.created_at}"
class Game(auto_prefetch.Model): class Game(models.Model):
"""The game the drop campaign is for. Note that some reward campaigns are not tied to a game.""" """The game the drop campaign is for. Note that some reward campaigns are not tied to a game."""
game_id = models.TextField(primary_key=True, help_text="The Twitch ID of the game.") game_id = models.TextField(primary_key=True, help_text="The Twitch ID of the game.")
@ -69,7 +68,7 @@ class Game(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text="When the game was first added to the database.") created_at = models.DateTimeField(auto_now_add=True, help_text="When the game was first added to the database.")
modified_at = models.DateTimeField(auto_now=True, help_text="When the game was last modified.") modified_at = models.DateTimeField(auto_now=True, help_text="When the game was last modified.")
class Meta(auto_prefetch.Model.Meta): class Meta:
ordering: ClassVar[list[str]] = ["display_name"] ordering: ClassVar[list[str]] = ["display_name"]
def __str__(self) -> str: def __str__(self) -> str:
@ -77,7 +76,7 @@ class Game(auto_prefetch.Model):
return f"{self.display_name or self.game_id} - {self.created_at}" return f"{self.display_name or self.game_id} - {self.created_at}"
class DropCampaign(auto_prefetch.Model): class DropCampaign(models.Model):
"""This is the drop campaign we will see on the front end.""" """This is the drop campaign we will see on the front end."""
campaign_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop campaign.") campaign_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop campaign.")
@ -89,14 +88,14 @@ class DropCampaign(auto_prefetch.Model):
image_url = models.URLField(blank=True, help_text="The URL to the image for the drop campaign.") image_url = models.URLField(blank=True, help_text="The URL to the image for the drop campaign.")
name = models.TextField(blank=True, help_text="The name of the drop campaign.") name = models.TextField(blank=True, help_text="The name of the drop campaign.")
status = models.TextField(blank=True, help_text="The status of the drop campaign.") status = models.TextField(blank=True, help_text="The status of the drop campaign.")
game = auto_prefetch.ForeignKey( game = models.ForeignKey(
to=Game, to=Game,
help_text="The game associated with this campaign", help_text="The game associated with this campaign",
null=True, null=True,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name="drop_campaigns", related_name="drop_campaigns",
) )
owner = auto_prefetch.ForeignKey( owner = models.ForeignKey(
Organization, Organization,
help_text="The organization running this campaign", help_text="The organization running this campaign",
null=True, null=True,
@ -110,7 +109,7 @@ class DropCampaign(auto_prefetch.Model):
) )
modified_at = models.DateTimeField(auto_now=True, help_text="When the drop campaign was last modified.") modified_at = models.DateTimeField(auto_now=True, help_text="When the drop campaign was last modified.")
class Meta(auto_prefetch.Model.Meta): class Meta:
ordering: ClassVar[list[str]] = ["end_at"] ordering: ClassVar[list[str]] = ["end_at"]
def __str__(self) -> str: def __str__(self) -> str:
@ -118,7 +117,7 @@ class DropCampaign(auto_prefetch.Model):
return f"{self.name or self.campaign_id} - {self.created_at}" return f"{self.name or self.campaign_id} - {self.created_at}"
class Benefit(auto_prefetch.Model): class Benefit(models.Model):
"""Represents a specific reward/benefit within a Drop.""" """Represents a specific reward/benefit within a Drop."""
benefit_id = models.TextField(primary_key=True, unique=True, help_text="Twitch's unique ID for the benefit") benefit_id = models.TextField(primary_key=True, unique=True, help_text="Twitch's unique ID for the benefit")
@ -130,8 +129,8 @@ class Benefit(auto_prefetch.Model):
image_asset_url = models.URLField(blank=True, help_text="The URL to the image for the benefit.") image_asset_url = models.URLField(blank=True, help_text="The URL to the image for the benefit.")
is_ios_available = models.BooleanField(null=True, help_text="If the benefit is farmable on iOS.") is_ios_available = models.BooleanField(null=True, help_text="If the benefit is farmable on iOS.")
name = models.TextField(blank=True, help_text="Name of the benefit/reward") name = models.TextField(blank=True, help_text="Name of the benefit/reward")
game = auto_prefetch.ForeignKey(Game, on_delete=models.SET_NULL, related_name="benefits", null=True) game = models.ForeignKey(Game, on_delete=models.SET_NULL, related_name="benefits", null=True)
owner_organization = auto_prefetch.ForeignKey( owner_organization = models.ForeignKey(
Organization, Organization,
on_delete=models.SET_NULL, on_delete=models.SET_NULL,
related_name="benefits", related_name="benefits",
@ -142,7 +141,7 @@ class Benefit(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True) created_at = models.DateTimeField(auto_now_add=True)
modified_at = models.DateTimeField(auto_now=True) modified_at = models.DateTimeField(auto_now=True)
class Meta(auto_prefetch.Model.Meta): class Meta:
ordering: ClassVar[list[str]] = ["-twitch_created_at"] ordering: ClassVar[list[str]] = ["-twitch_created_at"]
def __str__(self) -> str: def __str__(self) -> str:
@ -150,7 +149,7 @@ class Benefit(auto_prefetch.Model):
return f"{self.name or self.benefit_id} - {self.twitch_created_at}" return f"{self.name or self.benefit_id} - {self.twitch_created_at}"
class TimeBasedDrop(auto_prefetch.Model): class TimeBasedDrop(models.Model):
"""Represents a time-based drop within a Campaign.""" """Represents a time-based drop within a Campaign."""
drop_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop.") drop_id = models.TextField(primary_key=True, unique=True, help_text="The Twitch ID of the drop.")
@ -164,7 +163,7 @@ class TimeBasedDrop(auto_prefetch.Model):
start_at = models.DateTimeField(help_text="Drop start time") start_at = models.DateTimeField(help_text="Drop start time")
end_at = models.DateTimeField(help_text="Drop end time") end_at = models.DateTimeField(help_text="Drop end time")
campaign = auto_prefetch.ForeignKey( campaign = models.ForeignKey(
DropCampaign, DropCampaign,
help_text="The campaign this drop belongs to", help_text="The campaign this drop belongs to",
on_delete=models.CASCADE, on_delete=models.CASCADE,
@ -179,7 +178,7 @@ class TimeBasedDrop(auto_prefetch.Model):
created_at = models.DateTimeField(auto_now_add=True, help_text="When the drop was first added to the database.") created_at = models.DateTimeField(auto_now_add=True, help_text="When the drop was first added to the database.")
modified_at = models.DateTimeField(auto_now=True, help_text="When the drop was last modified.") modified_at = models.DateTimeField(auto_now=True, help_text="When the drop was last modified.")
class Meta(auto_prefetch.Model.Meta): class Meta:
ordering: ClassVar[list[str]] = ["required_minutes_watched"] ordering: ClassVar[list[str]] = ["required_minutes_watched"]
def __str__(self) -> str: def __str__(self) -> str:

View File

@ -10,27 +10,17 @@ dependencies = [
"django", "django",
"platformdirs", "platformdirs",
"python-dotenv", "python-dotenv",
"django-auto-prefetch",
] ]
# You can install development dependencies with `uv install --dev`.
# Or you can install them with `uv install --dev -r requirements-dev.txt`.
# uv can be replaced with `pip`if you don't have uv installed.
[dependency-groups] [dependency-groups]
dev = ["pre-commit", "pytest", "pytest-django", "ruff"] dev = ["pytest", "pytest-django"]
# https://docs.astral.sh/ruff/settings/
[tool.ruff] [tool.ruff]
# Enable all rules
lint.select = ["ALL"] lint.select = ["ALL"]
# https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html
lint.pydocstyle.convention = "google" lint.pydocstyle.convention = "google"
# Add "from __future__ import annotations" to all files
lint.isort.required-imports = ["from __future__ import annotations"] lint.isort.required-imports = ["from __future__ import annotations"]
line-length = 120
# Ignore some rules
lint.ignore = [ lint.ignore = [
"CPY001", # Checks for the absence of copyright notices within Python files. "CPY001", # Checks for the absence of copyright notices within Python files.
"D100", # Checks for undocumented public module definitions. "D100", # Checks for undocumented public module definitions.
@ -57,9 +47,6 @@ lint.ignore = [
"W191", # Checks for indentation that uses tabs. "W191", # Checks for indentation that uses tabs.
] ]
# Default is 88 characters
line-length = 120
[tool.ruff.lint.per-file-ignores] [tool.ruff.lint.per-file-ignores]
"**/tests/**" = [ "**/tests/**" = [
"ARG", # Unused function args -> fixtures nevertheless are functionally relevant... "ARG", # Unused function args -> fixtures nevertheless are functionally relevant...
@ -72,51 +59,22 @@ line-length = 120
"RUF012", # Checks for mutable default values in class attributes. "RUF012", # Checks for mutable default values in class attributes.
] ]
# https://www.djlint.com/
[tool.djlint] [tool.djlint]
# Set a profile for the template language. The profile will enable linter rules that apply to your template language, and may also change reformatting.
profile = "django" profile = "django"
# Formatter will attempt to format template syntax inside of tag attributes.
format_attribute_template_tags = true format_attribute_template_tags = true
# Format contents of style tags using css-beautify
format_css = true format_css = true
# Format contents of script tags using js-beautify.
format_js = true format_js = true
ignore = "H006"
# Ignore some rules
ignore = "H006" # Img tag should have height and width attributes.
# https://pytest-django.readthedocs.io/en/latest/
[tool.pytest.ini_options] [tool.pytest.ini_options]
# Where our Django settings are located.
DJANGO_SETTINGS_MODULE = "core.settings" DJANGO_SETTINGS_MODULE = "core.settings"
# Only run tests in files that match this pattern.
python_files = ["*_test.py"] python_files = ["*_test.py"]
# Enable logging in the console.
log_cli = true log_cli = true
log_cli_level = "INFO" log_cli_level = "INFO"
log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)" log_cli_format = "%(asctime)s [%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
log_cli_date_format = "%Y-%m-%d %H:%M:%S" log_cli_date_format = "%Y-%m-%d %H:%M:%S"
# Only check /tests/ directory for tests.
# This will speed up the test run significantly. (5.16s -> 0.25s)
testpaths = ["tests"] testpaths = ["tests"]
[tool.mypy]
plugins = ["mypy_django_plugin.main"]
[tool.django-stubs] [tool.django-stubs]
django_settings_module = "core.settings" django_settings_module = "core.settings"
[tool.black]
line-length = 120
preview = true
unstable = true
[tool.isort]
profile = "black"