Index: trunk/extensions/LiquidThreads/classes/LqtNewMessages.php |
— | — | @@ -94,7 +94,11 @@ |
95 | 95 | if ( $changeUser->getId() == $row->wl_user ) |
96 | 96 | continue; |
97 | 97 | |
98 | | - if ( $row->ums_user && !$row->ums_read_timestamp ) { |
| 98 | + if ( $row->ums_read_timestamp ) { |
| 99 | + $conds = array( 'ums_user' => $row->ums_user, |
| 100 | + 'ums_thread' => $t->id() ); |
| 101 | + $update_tuples[$row->ums_user.$t->id()] = $dbw->makeList( $conds, LIST_AND ); |
| 102 | + } elseif ( $row->ums_user ) { |
99 | 103 | // It's already positive. |
100 | 104 | } else { |
101 | 105 | $insert_rows[] = |
— | — | @@ -110,6 +114,9 @@ |
111 | 115 | } |
112 | 116 | } |
113 | 117 | |
| 118 | + // Avoids duplicates |
| 119 | + $update_tuples = array_values( $update_tuples ); |
| 120 | + |
114 | 121 | // Add user talk notification |
115 | 122 | if ( $t->article()->getTitle()->getNamespace() == NS_USER_TALK ) { |
116 | 123 | $name = $t->article()->getTitle()->getText(); |
— | — | @@ -118,9 +125,12 @@ |
119 | 126 | if ( $user ) { |
120 | 127 | $user->setNewtalk( true ); |
121 | 128 | |
122 | | - $insert_rows[] = array( 'ums_user' => $user->getId(), |
| 129 | + $dbw->replace( 'user_message_state', |
| 130 | + array( array( 'ums_user', 'ums_thread' ) ), |
| 131 | + array( 'ums_user' => $user->getId(), |
123 | 132 | 'ums_thread' => $t->id(), |
124 | | - 'ums_read_timestamp' => null ); |
| 133 | + 'ums_read_timestamp' => null ), |
| 134 | + __METHOD__ ); |
125 | 135 | |
126 | 136 | if ( $user->getOption( 'enotifusertalkpages' ) ) { |
127 | 137 | $notify_users[] = $user->getId(); |
— | — | @@ -131,9 +141,14 @@ |
132 | 142 | |
133 | 143 | // Do the actual updates |
134 | 144 | if ( count($insert_rows) ) { |
135 | | - $dbw->replace( 'user_message_state', array( array( 'ums_user', 'ums_thread' ) ), |
136 | | - $insert_rows, __METHOD__ ); |
| 145 | + $dbw->insert( 'user_message_state', $insert_rows, __METHOD__, array( 'IGNORE' ) ); |
137 | 146 | } |
| 147 | + if ( count($update_tuples) ) { |
| 148 | + $where = $dbw->makeList( $update_tuples, LIST_OR ); |
| 149 | + |
| 150 | + $dbw->update( 'user_message_state', array( 'ums_read_timestamp' => null ), |
| 151 | + array($where), __METHOD__ ); |
| 152 | + } |
138 | 153 | |
139 | 154 | if ( count($notify_users) ) { |
140 | 155 | self::notifyUsersByMail( $t, $notify_users, wfTimestampNow(), $type ); |