Initial commit

This commit is contained in:
2024-08-27 20:33:44 +02:00
commit 1f1832267d
14794 changed files with 1599592 additions and 0 deletions

View File

@@ -0,0 +1,51 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = []
operations = [
migrations.CreateModel(
name="Embed",
fields=[
(
"id",
models.AutoField(
verbose_name="ID",
primary_key=True,
auto_created=True,
serialize=False,
),
),
("url", models.URLField()),
("max_width", models.SmallIntegerField(null=True, blank=True)),
(
"type",
models.CharField(
max_length=10,
choices=[
("video", "Video"),
("photo", "Photo"),
("link", "Link"),
("rich", "Rich"),
],
),
),
("html", models.TextField(blank=True)),
("title", models.TextField(blank=True)),
("author_name", models.TextField(blank=True)),
("provider_name", models.TextField(blank=True)),
("thumbnail_url", models.URLField(null=True, blank=True)),
("width", models.IntegerField(null=True, blank=True)),
("height", models.IntegerField(null=True, blank=True)),
("last_updated", models.DateTimeField(auto_now=True)),
],
options={},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name="embed",
unique_together={("url", "max_width")},
),
]

View File

@@ -0,0 +1,15 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0001_initial"),
]
operations = [
migrations.AlterModelOptions(
name="embed",
options={"verbose_name": "Embed"},
),
]

View File

@@ -0,0 +1,15 @@
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0002_add_verbose_names"),
]
operations = [
migrations.AlterModelOptions(
name="embed",
options={"verbose_name": "embed"},
),
]

View File

@@ -0,0 +1,17 @@
# Generated by Django 2.2.dev20181026000358 on 2018-10-27 09:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0003_capitalizeverbose"),
]
operations = [
migrations.AlterModelOptions(
name="embed",
options={"verbose_name": "embed", "verbose_name_plural": "embeds"},
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 2.1.7 on 2019-03-04 08:49
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0004_embed_verbose_name_plural"),
]
operations = [
migrations.AlterField(
model_name="embed",
name="thumbnail_url",
field=models.URLField(blank=True, max_length=255, null=True),
),
]

View File

@@ -0,0 +1,16 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0005_specify_thumbnail_url_max_length"),
]
operations = [
migrations.AddField(
model_name="embed",
name="hash",
field=models.CharField(blank=True, max_length=32),
),
]

View File

@@ -0,0 +1,51 @@
from django.db import migrations
from django.db.models import Count, Min
from wagtail.embeds.embeds import get_embed_hash
def migrate_forwards(apps, schema_editor):
Embed = apps.get_model("wagtailembeds.Embed")
# based each embed being ~500b, available memory being
# to 2MB, and leaving plenty of headway for app itself
batch_size = 1500
# allows small batches to be kept in memory in order
# to utilise bulk_update()
batch = []
for embed in Embed.objects.all().only("id", "url", "max_width").iterator():
embed.hash = get_embed_hash(embed.url, embed.max_width)
batch.append(embed)
if len(batch) == batch_size:
# save and reset current batch
Embed.objects.bulk_update(batch, ["hash"])
batch.clear()
# save any leftovers
if batch:
Embed.objects.bulk_update(batch, ["hash"])
# delete duplicates
duplicates = (
Embed.objects.values("hash")
.annotate(hash_count=Count("id"), min_id=Min("id"))
.filter(hash_count__gt=1)
)
for dup in duplicates:
# for each duplicated hash, delete all except the one with the lowest id
Embed.objects.filter(hash=dup["hash"]).exclude(id=dup["min_id"]).delete()
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0006_add_embed_hash"),
]
operations = [
migrations.RunPython(migrate_forwards, migrations.RunPython.noop),
]

View File

@@ -0,0 +1,48 @@
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0007_populate_hash"),
]
operations = [
migrations.AlterField(
model_name="embed",
name="hash",
field=models.CharField(db_index=True, max_length=32, unique=True),
),
# MySQL needs max length on the unique together fields.
# Drop unique together before alter char to text.
migrations.AlterUniqueTogether(
name="embed",
unique_together=set(),
),
migrations.AlterField(
model_name="embed",
name="url",
field=models.TextField(),
),
# Converting URLField to TextField with a default specified (even with preserve_default=False)
# fails with Django 3.0 and MySQL >=8.0.13 (see https://code.djangoproject.com/ticket/32503) -
# work around this by altering in two stages, first making the URLField non-null then converting
# to TextField
migrations.AlterField(
model_name="embed",
name="thumbnail_url",
field=models.URLField(
blank=True,
default="",
max_length=255,
),
preserve_default=False,
),
migrations.AlterField(
model_name="embed",
name="thumbnail_url",
field=models.TextField(
blank=True,
),
),
]

View File

@@ -0,0 +1,18 @@
# Generated by Django 3.1.7 on 2021-04-07 19:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailembeds", "0008_allow_long_urls"),
]
operations = [
migrations.AddField(
model_name="embed",
name="cache_until",
field=models.DateTimeField(blank=True, db_index=True, null=True),
),
]