From ca2454eeb4fda697616fc5f25659ab06c0602546 Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Sat, 23 Apr 2016 00:06:34 +0200 Subject: [PATCH] Avoid write operations if not needed --- mod/display.php | 12 ++++++++---- mod/network.php | 22 ++++++++++++++++------ 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/mod/display.php b/mod/display.php index e53f9e2066..fbbd263172 100644 --- a/mod/display.php +++ b/mod/display.php @@ -437,10 +437,14 @@ function display_content(&$a, $update = 0) { if($r) { if((local_user()) && (local_user() == $a->profile['uid'])) { - q("UPDATE `item` SET `unseen` = 0 - WHERE `parent` = %d AND `unseen`", - intval($r[0]['parent']) - ); + $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `parent` = %d", + intval($r[0]['parent'])); + + if ($unseen) + q("UPDATE `item` SET `unseen` = 0 + WHERE `parent` = %d AND `unseen`", + intval($r[0]['parent']) + ); } $items = conv_sort($r,"`commented`"); diff --git a/mod/network.php b/mod/network.php index a9f369a894..95efc36260 100644 --- a/mod/network.php +++ b/mod/network.php @@ -857,14 +857,24 @@ function network_content(&$a, $update = 0) { if((! $group) && (! $cid) && (! $star)) { - $r = q("UPDATE `item` SET `unseen` = 0 - WHERE `unseen` = 1 AND `uid` = %d", - intval(local_user()) - ); + + $unseen = q("SELECT `id` FROM `item` WHERE `unseen` AND `uid` = %d", + intval(local_user())); + + if ($unseen) + $r = q("UPDATE `item` SET `unseen` = 0 + WHERE `unseen` = 1 AND `uid` = %d", + intval(local_user()) + ); } else { - if($update_unseen) - $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen"); + if($update_unseen) { + + $unseen = q("SELECT `id` FROM `item` ".$update_unseen); + + if ($unseen) + $r = q("UPDATE `item` SET `unseen` = 0 $update_unseen"); + } } // Set this so that the conversation function can find out contact info for our wall-wall items