Skip to content

Commit

Permalink
[#2562] use read connection for read operations
Browse files Browse the repository at this point in the history
  • Loading branch information
wardi committed Sep 1, 2017
1 parent a13c38c commit 6504152
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions ckanext/datastore/backend/postgres.py
Expand Up @@ -1459,7 +1459,7 @@ def upsert(context, data_dict):

def search(context, data_dict):
backend = DatastorePostgresqlBackend.get_active_backend()
engine = backend._get_write_engine()
engine = backend._get_read_engine()
context['connection'] = engine.connect()
timeout = context.get('query_timeout', _TIMEOUT)
_cache_types(context)
Expand Down Expand Up @@ -1860,15 +1860,15 @@ def resource_exists(self, id):
resources_sql = sqlalchemy.text(
u'''SELECT 1 FROM "_table_metadata"
WHERE name = :id AND alias_of IS NULL''')
results = self._get_write_engine().execute(resources_sql, id=id)
results = self._get_read_engine().execute(resources_sql, id=id)
res_exists = results.rowcount > 0
return res_exists

def resource_id_from_alias(self, alias):
real_id = None
resources_sql = sqlalchemy.text(u'''SELECT alias_of FROM "_table_metadata"
WHERE name = :id''')
results = self._get_write_engine().execute(resources_sql, id=alias)
results = self._get_read_engine().execute(resources_sql, id=alias)

res_exists = results.rowcount > 0
if res_exists:
Expand Down Expand Up @@ -1896,7 +1896,7 @@ def _type_lookup(t):
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_name = :resource_id;
''')
schema_results = self._get_write_engine().execute(
schema_results = self._get_read_engine().execute(
schema_sql, resource_id=id)
for row in schema_results.fetchall():
k = row[0]
Expand All @@ -1910,7 +1910,7 @@ def _type_lookup(t):
meta_sql = sqlalchemy.text(u'''
SELECT count(_id) FROM "{0}";
'''.format(id))
meta_results = self._get_write_engine().execute(
meta_results = self._get_read_engine().execute(
meta_sql, resource_id=id)
info['meta']['count'] = meta_results.fetchone()[0]
finally:
Expand All @@ -1924,7 +1924,7 @@ def get_all_ids(self):
resources_sql = sqlalchemy.text(
u'''SELECT name FROM "_table_metadata"
WHERE alias_of IS NULL''')
query = self._get_write_engine().execute(resources_sql)
query = self._get_read_engine().execute(resources_sql)
return [q[0] for q in query.fetchall()]

def create_function(self, *args, **kwargs):
Expand Down

0 comments on commit 6504152

Please sign in to comment.