Skip to content

Instantly share code, notes, and snippets.

@wlmcewen
Created February 22, 2017 16:40
Show Gist options
  • Save wlmcewen/7dc940a7bd939fdce8de1fd93d2636b9 to your computer and use it in GitHub Desktop.
Save wlmcewen/7dc940a7bd939fdce8de1fd93d2636b9 to your computer and use it in GitHub Desktop.
ARMLS-2782
prospector=# select source_id, event, event_created_at, newsfeed_id from newsfeed_item_event where newsfeed_item_id = 1229312741
order by event_created_at desc;
source_id | event | event_created_at | newsfeed_id
----------------------------+-------+----------------------------+-------------
20160910213418695892000000 | 4 | 2017-02-15 22:02:41.580145 | 12693041
20160910213418695892000000 | 5 | 2017-01-28 11:46:03.819968 | 12693041
20160910213418695892000000 | 1 | 2016-12-05 11:16:32.197197 | 12693041
20160910213418695892000000 | 0 | 2016-09-10 19:29:29.05982 | 12693041
prospector=# select current_status, resource_match_status, newsfeed_item_updated_at, newsfeed_item_created_at from newsfeed_item where newsfeed_id = 12693041 and source_id = '20160910213418695892000000';
current_status | resource_match_status | newsfeed_item_updated_at | newsfeed_item_created_at
----------------+-----------------------+----------------------------+---------------------------
Pending | Pending | 2017-02-15 22:02:41.580145 | 2016-09-10 19:29:29.05982
(1 row)
prospector=# SELECT newsfeed_item_event.newsfeed_item_id, newsfeed_item_event.source_id, MAX(newsfeed_item_event_id) as newsfeed_item_event_id, MAX(event_created_at) as last_event_at FROM "newsfeed_item_event" WHERE "newsfeed_item_event"."subscriber_id" IN ('20081222164733283281000000') AND "newsfeed_item_event"."mls_id" = '20070913202326493241000000' AND (newsfeed_item_event.newsfeed_id=12693041 AND EXISTS (SELECT 1 FROM newsfeed_item WHERE newsfeed_item.newsfeed_item_id = newsfeed_item_event.newsfeed_item_id AND (current_status IN ('Active','Active Under Contract','Canceled','Closed','Coming Soon','Expired','Hold','Pending','Withdrawn') AND (current_status NOT IN ('Active','Pending','Canceled','Closed','Expired','Withdrawn','Active Under Contract') OR current_status = resource_match_status) OR current_status IS NULL) AND (source_view_restricted = 'f' OR source_view_restricted is null)) AND ((EXISTS (SELECT 1 FROM newsfeed_item WHERE newsfeed_item.newsfeed_item_id = newsfeed_item_event.newsfeed_item_id AND newsfeed_item_approved = 't')))) and source_id = '20160910213418695892000000' GROUP BY newsfeed_item_event.newsfeed_item_id, newsfeed_item_event.source_id ORDER BY last_event_at desc, newsfeed_item_event.newsfeed_item_id desc LIMIT 50 OFFSET 0;
newsfeed_item_id | source_id | newsfeed_item_event_id | last_event_at
------------------+----------------------------+------------------------+----------------------------
1229312741 | 20160910213418695892000000 | 2807124813 | 2017-02-15 22:02:41.580145
(1 row)
prospector=# SELECT newsfeed_item_event.source_id, (array_agg(newsfeed_item_event.newsfeed_item_id ORDER BY event_created_at desc, newsfeed_item_event.newsfeed_item_event_id desc))[1] as newsfeed_item_id, MAX(newsfeed_item_event_id) as newsfeed_item_event_id, MAX(event_created_at) as last_event_at FROM "newsfeed_item_event" WHERE "newsfeed_item_event"."subscriber_id" IN ('20081222164733283281000000') AND "newsfeed_item_event"."mls_id" = '20070913202326493241000000' AND (EXISTS (SELECT 1 FROM newsfeed_item WHERE newsfeed_item.newsfeed_item_id = newsfeed_item_event.newsfeed_item_id AND (current_status IN ('Active','Active Under Contract','Canceled','Closed','Coming Soon','Expired','Hold','Pending','Withdrawn') AND (current_status NOT IN ('Active','Pending','Canceled','Closed','Expired','Withdrawn','Active Under Contract') OR current_status = resource_match_status) OR current_status IS NULL) AND (source_view_restricted = 'f' OR source_view_restricted is null)) AND ((EXISTS (SELECT 1 FROM newsfeed_item WHERE newsfeed_item.newsfeed_item_id = newsfeed_item_event.newsfeed_item_id AND newsfeed_item_approved = 't')))) and source_id = '20160910213418695892000000' GROUP BY newsfeed_item_event.source_id ORDER BY last_event_at desc, newsfeed_item_event.source_id desc LIMIT 5 OFFSET 0;
source_id | newsfeed_item_id | newsfeed_item_event_id | last_event_at
----------------------------+------------------+------------------------+----------------------------
20160910213418695892000000 | 1229312741 | 2807124813 | 2017-02-15 22:02:41.580145
SparkApi:016:0> pp get("/contacts/20081222164733283281000000/newsfeeds/events", _pagination: 1, _page: 1, _select: "ListingKey", _filter: "NotificationSent Eq true And Approved Eq true", _limit: 200, RoleOverride: "public").select { |i| i["Id"] == '20160910213418695892000000' }.first
{"Id"=>"20160910213418695892000000",
"ResourceUri"=>"/v1/listings/20160910213418695892000000",
"StandardFields"=>
{"ListingKey"=>"20160910213418695892000000",
"MlsId"=>"20070913202326493241000000",
"Photos"=>
[{"ResourceUri"=>
"/v1/listings/20160910213418695892000000/photos/20160911001338049662000000",
"Id"=>"20160911001338049662000000",
"Name"=>"01 2015-11-20 14.36.46",
"Caption"=>"",
"UriThumb"=>
"https://cdn.photos.sparkplatform.com/az/20160911001338049662000000-t.jpg",
"Uri300"=>
"https://cdn.photos.sparkplatform.com/az/20160911001338049662000000.jpg",
"Uri640"=>
"https://cdn.resize.sparkplatform.com/az/640x480/true/20160911001338049662000000-o.jpg",
"Uri800"=>
"https://cdn.resize.sparkplatform.com/az/800x600/true/20160911001338049662000000-o.jpg",
"Uri1024"=>
"https://cdn.resize.sparkplatform.com/az/1024x768/true/20160911001338049662000000-o.jpg",
"Uri1280"=>
"https://cdn.resize.sparkplatform.com/az/1280x1024/true/20160911001338049662000000-o.jpg",
"Uri1600"=>
"https://cdn.resize.sparkplatform.com/az/1600x1200/true/20160911001338049662000000-o.jpg",
"Uri2048"=>
"https://cdn.resize.sparkplatform.com/az/2048x1600/true/20160911001338049662000000-o.jpg",
"UriLarge"=>
"https://cdn.photos.sparkplatform.com/az/20160911001338049662000000-o.jpg",
"Primary"=>true}]},
"LastCachedTimestamp"=>"2017-02-22T16:09:51Z",
"DisplayCompliance"=>{"View"=>"Summary"},
"NewsFeed"=>
{"Type"=>"Listing",
"Events"=>["Pending"],
"LastEventTimestamp"=>"2017-02-16T04:02:41Z",
"Viewed"=>false,
"Approved"=>true,
"NotificationSent"=>true,
"Restricted"=>false}}
SparkApi:015:0> pp get("/contacts/20081222164733283281000000/newsfeeds/20160213173417700199693041/events", _pagination: 1, _page: 1, _select: "ListingKey", _filter: "NotificationSent Eq true And Approved Eq true", _limit: 200, RoleOverride: "public").select { |i| i["Id"] == '20160910213418695892000000' }.first
{"Id"=>"20160910213418695892000000",
"ResourceUri"=>"/v1/listings/20160910213418695892000000",
"StandardFields"=>
{"ListingKey"=>"20160910213418695892000000",
"MlsId"=>"20070913202326493241000000",
"Photos"=>
[{"ResourceUri"=>
"/v1/listings/20160910213418695892000000/photos/20160911001338049662000000",
"Id"=>"20160911001338049662000000",
"Name"=>"01 2015-11-20 14.36.46",
"Caption"=>"",
"UriThumb"=>
"https://cdn.photos.sparkplatform.com/az/20160911001338049662000000-t.jpg",
"Uri300"=>
"https://cdn.photos.sparkplatform.com/az/20160911001338049662000000.jpg",
"Uri640"=>
"https://cdn.resize.sparkplatform.com/az/640x480/true/20160911001338049662000000-o.jpg",
"Uri800"=>
"https://cdn.resize.sparkplatform.com/az/800x600/true/20160911001338049662000000-o.jpg",
"Uri1024"=>
"https://cdn.resize.sparkplatform.com/az/1024x768/true/20160911001338049662000000-o.jpg",
"Uri1280"=>
"https://cdn.resize.sparkplatform.com/az/1280x1024/true/20160911001338049662000000-o.jpg",
"Uri1600"=>
"https://cdn.resize.sparkplatform.com/az/1600x1200/true/20160911001338049662000000-o.jpg",
"Uri2048"=>
"https://cdn.resize.sparkplatform.com/az/2048x1600/true/20160911001338049662000000-o.jpg",
"UriLarge"=>
"https://cdn.photos.sparkplatform.com/az/20160911001338049662000000-o.jpg",
"Primary"=>true}]},
"LastCachedTimestamp"=>"2017-02-22T16:09:51Z",
"DisplayCompliance"=>{"View"=>"Summary"},
"NewsFeed"=>
{"Type"=>"Listing",
"Events"=>["Pending"],
"LastEventTimestamp"=>"2017-02-16T04:02:41Z",
"Viewed"=>false,
"Approved"=>true,
"NotificationSent"=>true,
"Restricted"=>false}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment