Ticket #868: postgres_speed.diff

File postgres_speed.diff, 1.9 KB (added by kindly@…, 3 years ago)

Speed up postgres by making sure postgres does not drop and reacreate each time.

  • ckan/model/__init__.py

    diff -r ba5615dcf132 ckan/model/__init__.py
    a b  
    4242class Repository(vdm.sqlalchemy.Repository): 
    4343    migrate_repository = ckan.migration.__path__[0] 
    4444 
     45    inited = False 
     46 
    4547    def init_db(self, conditional=False): 
    46         if conditional: 
    47             already_done = Session.connection()\ 
    48                            .engine.has_table("user") 
    49         else: 
    50             already_done = False 
    51         if not already_done: 
     48        #sqlite database needs to be recreted each time as the memory database 
     49        #is lost. 
     50        if not self.inited or self.metadata.bind.name == 'sqlite': 
    5251            super(Repository, self).init_db() 
     52 
     53        self.session.rollback() 
     54        self.session.remove() 
    5355        self.add_initial_data() 
    5456 
    5557    def add_initial_data(self): 
     
    98100        else: 
    99101            tables = reversed(metadata.sorted_tables) 
    100102        for table in tables: 
    101             connection.execute('drop table "%s"' % table.name) 
     103            connection.execute('delete from "%s"' % table.name) 
    102104        self.session.commit() 
    103         #self.add_initial_data() 
     105        self.add_initial_data() 
    104106 
    105107    def setup_migration_version_control(self, version=None): 
    106108        import migrate.versioning.exceptions 
  • ckan/tests/__init__.py

    diff -r ba5615dcf132 ckan/tests/__init__.py
    a b  
    5656cmd.run([config_path]) 
    5757 
    5858import ckan.model as model 
    59 model.repo.rebuild_db() 
     59model.repo.init_db() 
     60 
     61#make sure that the database is droped and recreated first 
     62#so that any schema changes will be made. 
     63model.repo.metadata.drop_all(bind=model.repo.metadata.bind) 
     64model.repo.init_db() 
     65#tell repo it does not need to drop and craete any more 
     66model.repo.inited = True 
    6067 
    6168class BaseCase(object): 
    6269