Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Make populatedb several times faster on sqlite3
Patryk Zawadzki0f0844f0a315
diff --git a/saleor/product/management/commands/populatedb.py b/saleor/product/management/commands/populatedb.pyindex 0d6a4d27c9..e89aff69bb 100644--- a/saleor/product/management/commands/populatedb.py+++ b/saleor/product/management/commands/populatedb.py@@ -1,8 +1,8 @@from django.core.management.base import BaseCommand--from utils.create_random_data import create_items, create_users, create_orders+from django.db import connectionfrom saleor.userprofile.models import User+from utils.create_random_data import create_items, create_users, create_ordersclass Command(BaseCommand):@@ -17,10 +17,22 @@ class Command(BaseCommand):default=False,help='Create admin account')+ def make_database_faster(self):+ '''Sacrifices some of the safeguards of sqlite3 for speed++ Users are not likely to run this command in a production environment.+ They are even less likely to run it in production while using sqlite3.+ '''+ if 'sqlite3' in connection.settings_dict['ENGINE']:+ cursor = connection.cursor()+ cursor.execute('PRAGMA temp_store = MEMORY;')+ cursor.execute('PRAGMA synchronous = OFF;')+def handle(self, *args, **options):- for msg in create_items(self.placeholders_dir, 10):+ self.make_database_faster()+ for msg in create_items(self.placeholders_dir, 20):self.stdout.write(msg)- for msg in create_users(10):+ for msg in create_users(20):self.stdout.write(msg)for msg in create_orders(20):self.stdout.write(msg)