v/pol
1
0
mirror of https://github.com/taroved/pol synced 2025-05-28 03:50:08 -07:00

reduse db size

This commit is contained in:
Alexandr Nesterenko 2018-02-15 19:14:19 +03:00
parent 6d037ba784
commit 2abe04457c
3 changed files with 52 additions and 1 deletions

View File

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-10 22:54
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('frontend', '0005_auto_20180131_1949'),
]
operations = [
migrations.AddField(
model_name='feed',
name='owner',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL),
),
]

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.10 on 2018-02-15 14:45
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('frontend', '0007_auto_20180211_0027'),
]
operations = [
migrations.RunSQL("ALTER TABLE `frontend_post` ADD COLUMN `md5sum2` BINARY(16) DEFAULT 0 NOT NULL;"
"UPDATE `frontend_post` set `md5sum2` = unhex(`md5sum`);"
"ALTER TABLE frontend_post DROP COLUMN md5sum;"
"ALTER TABLE frontend_post CHANGE COLUMN md5sum2 md5sum BINARY(16) NOT NULL;"
"CREATE INDEX md5sum_index USING HASH ON frontend_post (feed_id, md5sum);",
state_operations=[
migrations.AlterField(
model_name='post',
name='md5sum',
field=models.BinaryField(),
),
]),
]

View File

@ -33,9 +33,10 @@ class Feed(object):
def save_post(self, conn, created, feed_id, post_fields):
with conn as cur:
cur.execute("""insert into frontend_post (md5sum, created, feed_id)
values (%s, %s, %s)""", (post_fields['md5'], created, feed_id))
values (unhex(%s), %s, %s)""", (post_fields['md5'], created, feed_id))
post_id = conn.insert_id()
log.info('Post saved id:{id!r}', id=post_id)
return post_id
def fill_time(self, feed_id, items):
if not items: