Use very fancy SQL nonsense
This should be more efficient than running the queries one by one
This commit is contained in:
parent
ee7388052c
commit
717cbe3034
|
@ -4,6 +4,7 @@ from django.db import migrations, models
|
||||||
from django.db import connection
|
from django.db import connection
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
import django.db.models.deletion
|
import django.db.models.deletion
|
||||||
|
from psycopg2.extras import execute_values
|
||||||
|
|
||||||
def convert_review_rating(app_registry, schema_editor):
|
def convert_review_rating(app_registry, schema_editor):
|
||||||
''' take rating type Reviews and convert them to ReviewRatings '''
|
''' take rating type Reviews and convert them to ReviewRatings '''
|
||||||
|
@ -16,11 +17,10 @@ def convert_review_rating(app_registry, schema_editor):
|
||||||
)
|
)
|
||||||
|
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
for review in reviews:
|
values = [(r.id,) for r in reviews]
|
||||||
cursor.execute('''
|
execute_values(cursor, '''
|
||||||
INSERT INTO bookwyrm_reviewrating(review_ptr_id)
|
INSERT INTO bookwyrm_reviewrating(review_ptr_id)
|
||||||
SELECT status_ptr_id FROM bookwyrm_review
|
VALUES %s''', values)
|
||||||
WHERE status_ptr_id=%s''', (review.id))
|
|
||||||
|
|
||||||
def unconvert_review_rating(app_registry, schema_editor):
|
def unconvert_review_rating(app_registry, schema_editor):
|
||||||
''' undo the conversion from ratings back to reviews'''
|
''' undo the conversion from ratings back to reviews'''
|
||||||
|
|
Loading…
Reference in New Issue