From a0fab2b584aa58505c770bdf5ec86bd949ed69e1 Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Mon, 10 Mar 2014 00:17:34 -0500 Subject: [PATCH] mod the get_work stored procedure to exclude all connections but those which are from clients. --- db/manifest | 1 + db/up/update_get_work_for_client_type.sql | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 db/up/update_get_work_for_client_type.sql diff --git a/db/manifest b/db/manifest index 92caba43c..f04a8c89d 100755 --- a/db/manifest +++ b/db/manifest @@ -131,3 +131,4 @@ connection_client_type.sql add_countries_regions_and_cities.sql plays_refactor.sql fix_max_mind_isp_and_geo.sql +update_get_work_for_client_type.sql diff --git a/db/up/update_get_work_for_client_type.sql b/db/up/update_get_work_for_client_type.sql new file mode 100644 index 000000000..cd356eef7 --- /dev/null +++ b/db/up/update_get_work_for_client_type.sql @@ -0,0 +1,16 @@ +DROP FUNCTION get_work (mylocidispid BIGINT); +CREATE FUNCTION get_work (mylocidispid BIGINT) RETURNS TABLE (client_id VARCHAR(64)) ROWS 5 VOLATILE AS $$ +BEGIN + CREATE TEMPORARY TABLE foo (locidispid BIGINT, locid INT); + INSERT INTO foo SELECT DISTINCT locidispid, locidispid/1000000 FROM connections where client_type = 'client'; + DELETE FROM foo WHERE locidispid IN (SELECT DISTINCT blocidispid FROM current_scores WHERE alocidispid = mylocidispid AND (current_timestamp - score_dt) < interval '24 hours'); + DELETE FROM foo WHERE locid NOT IN (SELECT locid FROM geoiplocations WHERE geog && st_buffer((SELECT geog from geoiplocations WHERE locid = mylocidispid/1000000), 806000)); + CREATE TEMPORARY TABLE bar (client_id VARCHAR(64), locidispid BIGINT, r DOUBLE PRECISION); + INSERT INTO bar SELECT l.client_id, l.locidispid, random() FROM connections l, foo f WHERE l.locidispid = f.locidispid and l.client_type = 'client'; + DROP TABLE foo; + DELETE FROM bar b WHERE r != (SELECT max(r) FROM bar b0 WHERE b0.locidispid = b.locidispid); + RETURN QUERY SELECT b.client_id FROM bar b ORDER BY r LIMIT 5; + DROP TABLE bar; + RETURN; +END; +$$ LANGUAGE plpgsql;