Fix #5368 - Improve test efficiancy
authorJessica Tallon <tsyesika@tsyesika.se>
Mon, 28 Dec 2015 12:55:33 +0000 (12:55 +0000)
committerJessica Tallon <tsyesika@tsyesika.se>
Tue, 29 Dec 2015 16:42:37 +0000 (16:42 +0000)
There were a number of tests where lots of models where being iterated through
and then at the end committing them. The problem is all the changes had to be
kept in memory or on disk somewhere before they were commit to the database. This
fix commits each change as it's being made, allowing resources to be freed and fixing
some of the inefficiencies

mediagoblin/db/migrations.py

index 461b9c0a9232c55bc09f96c9b613d8e570c94997..1c159511c09810dd243bb45be6161c9692997641 100644 (file)
@@ -1371,8 +1371,9 @@ def migrate_data_foreign_keys(db):
             temp_object=target_gmr.inserted_primary_key[0]
         ))
 
-    # Commit to the database.
-    db.commit()
+        # Commit to the database. We're doing it here rather than outside the
+        # loop because if the server has a lot of data this can cause problems.
+        db.commit()
 
 @RegisterMigration(30, MIGRATIONS)
 def rename_and_remove_object_and_target(db):
@@ -1522,7 +1523,7 @@ def federation_user_migrate_data(db):
             type=LocalUser.__mapper_args__["polymorphic_identity"]
         ))
 
-    db.commit()
+        db.commit()
 
 class User_vR2(declarative_base()):
     __tablename__ = "rename__users"
@@ -1618,7 +1619,7 @@ def federation_media_entry(db):
             remote=False
         ))
 
-    db.commit()
+        db.commit()
 
 @RegisterMigration(36, MIGRATIONS)
 def create_oauth1_dummies(db):