From f58d8f410885bb1895821cd0767bdf981629f0cd Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Tue, 27 Feb 2018 20:47:18 -0500 Subject: [PATCH 1/2] Add attendance check to event reminder --- mod/network.php | 4 ++-- mod/profile.php | 2 +- src/Model/Profile.php | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/mod/network.php b/mod/network.php index 2d9a829ce..5b9e2a6fb 100644 --- a/mod/network.php +++ b/mod/network.php @@ -439,7 +439,7 @@ function networkFlatView(App $a, $update = 0) if (!Config::get('theme', 'hide_eventlist')) { $o .= Profile::getBirthdays(); - $o .= Profile::getEvents(); + $o .= Profile::getEventsReminderHTML(); } } @@ -677,7 +677,7 @@ function networkThreadedView(App $a, $update = 0) if (!$gid && !$cid && !$update && !Config::get('theme', 'hide_eventlist')) { $o .= Profile::getBirthdays(); - $o .= Profile::getEvents(); + $o .= Profile::getEventsReminderHTML(); } if ($datequery) { diff --git a/mod/profile.php b/mod/profile.php index 74ca06aad..5e5988994 100644 --- a/mod/profile.php +++ b/mod/profile.php @@ -352,7 +352,7 @@ function profile_content(App $a, $update = 0) if ($is_owner && !$update && !Config::get('theme', 'hide_eventlist')) { $o .= Profile::getBirthdays(); - $o .= Profile::getEvents(); + $o .= Profile::getEventsReminderHTML(); } diff --git a/src/Model/Profile.php b/src/Model/Profile.php index 81f996309..c91fdc1a9 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -622,7 +622,7 @@ class Profile ]); } - public static function getEvents() + public static function getEventsReminderHTML() { $a = get_app(); $o = ''; @@ -642,9 +642,21 @@ class Profile $classtoday = ''; $s = dba::p( - "SELECT `event`.* FROM `event` - WHERE `event`.`uid` = ? AND `type` != 'birthday' AND `start` < ? AND `start` >= ? - ORDER BY `start` ASC ", + "SELECT `event`.*, `item`.`id`, `item`.`thr-parent`, `item`.`parent-uri` + FROM `event` + LEFT JOIN `item` + ON `item`.`uid` = `event`.`uid` + AND `item`.`parent-uri` = `event`.`uri` + AND `item`.`verb` = ? + AND `item`.`visible` + AND NOT `item`.`deleted` + WHERE `event`.`uid` = ? + AND `event`.`type` != 'birthday' + AND `event`.`start` < ? + AND `event`.`start` >= ? + AND `item`.`id` IS NULL + ORDER BY `event`.`start` ASC", + ACTIVITY_ATTENDNO, local_user(), DateTimeFormat::utc('now + 7 days'), DateTimeFormat::utc('now - 1 days') From 4d3ea08c9775aa101ef5e1cbd9c75d31c084d825 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Wed, 28 Feb 2018 08:50:01 -0500 Subject: [PATCH 2/2] Use NOT EXISTS to improve performance --- src/Model/Profile.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Model/Profile.php b/src/Model/Profile.php index c91fdc1a9..e493d82d5 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -642,24 +642,26 @@ class Profile $classtoday = ''; $s = dba::p( - "SELECT `event`.*, `item`.`id`, `item`.`thr-parent`, `item`.`parent-uri` + "SELECT * FROM `event` - LEFT JOIN `item` - ON `item`.`uid` = `event`.`uid` - AND `item`.`parent-uri` = `event`.`uri` - AND `item`.`verb` = ? - AND `item`.`visible` - AND NOT `item`.`deleted` WHERE `event`.`uid` = ? AND `event`.`type` != 'birthday' AND `event`.`start` < ? AND `event`.`start` >= ? - AND `item`.`id` IS NULL + AND NOT EXISTS ( + SELECT `id` + FROM `item` + WHERE `item`.`uid` = `event`.`uid` + AND `item`.`parent-uri` = `event`.`uri` + AND `item`.`verb` = ? + AND `item`.`visible` + AND NOT `item`.`deleted` + ) ORDER BY `event`.`start` ASC", - ACTIVITY_ATTENDNO, local_user(), DateTimeFormat::utc('now + 7 days'), - DateTimeFormat::utc('now - 1 days') + DateTimeFormat::utc('now - 1 days'), + ACTIVITY_ATTENDNO ); $r = [];