Refactor, extracted user_service
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# cdb_conf geocoder config example
|
||||
INSERT INTO cdb_conf VALUES ('geocoder_conf', '{"geocoder_db": {"host": "localhost", "port": "5432", db": "cartodb_dev_user_274bf952-8568-4598-9efd-be92ed3d2ead_db", "user": "development_cartodb_user_274bf952-8568-4598-9efd-be92ed3d2ead"}, "redis": {"host": "localhost", "port": 6379, "db": 5 } }')
|
||||
|
||||
CREATE OR REPLACE FUNCTION cartodb._Geocoder_Admin0_Polygons(search text)
|
||||
CREATE OR REPLACE FUNCTION cartodb._geocoder_admin0_polygons(search text)
|
||||
RETURNS Geometry AS
|
||||
$$
|
||||
db_connection_str = plpy.execute("SELECT * FROM cartodb._Geocoder_Server_Conf() conf;")[0]['conf']
|
||||
@@ -9,7 +9,7 @@ $$
|
||||
$$ LANGUAGE plpythonu SECURITY DEFINER;
|
||||
|
||||
CREATE OR REPLACE
|
||||
FUNCTION cartodb._Geocoder_Server_Conf()
|
||||
FUNCTION cartodb._geocoder_server_conf()
|
||||
RETURNS text AS
|
||||
$$
|
||||
conf = plpy.execute("SELECT cartodb.CDB_Conf_GetConf('geocoder_conf') conf")[0]['conf']
|
||||
@@ -22,7 +22,7 @@ $$
|
||||
return "host={0} port={1} dbname={2} user={3}".format(db_params['host'],db_params['port'],db_params['db'],db_params['user'])
|
||||
$$ LANGUAGE 'plpythonu';
|
||||
|
||||
CREATE OR REPLACE FUNCTION cartodb._Geocoder_Admin0_Polygons(search text, user_id name, tx_id bigint, db_connection_str text)
|
||||
CREATE OR REPLACE FUNCTION cartodb._geocoder_admin0_polygons(search text, user_id name, tx_id bigint, db_connection_str text)
|
||||
RETURNS Geometry AS $$
|
||||
CONNECT db_connection_str;
|
||||
SELECT geocode_admin0(search, tx_id, user_id);
|
||||
|
||||
@@ -17,8 +17,8 @@ $$
|
||||
if qs.check_user_quota():
|
||||
result = plpy.execute("SELECT geom FROM geocode_admin0_polygons(Array[\'{0}\']::text[])".format(search))
|
||||
if result.status() == 5 and result.nrows() == 1:
|
||||
qs.increment_georeference_use()
|
||||
SD[user_id] = {tx_id: {'redis_connection': qs.get_redis_connection()}}
|
||||
qs.increment_geocoder_use()
|
||||
SD[user_id] = {tx_id: {'redis_connection': qs.get_user_service().get_redis_connection()}}
|
||||
return result[0]["geom"]
|
||||
else:
|
||||
raise Exception('Something wrong with the georefence operation')
|
||||
|
||||
Reference in New Issue
Block a user