Archived
1
0

Database refactoring and improving blog comments, blog post history and more

This commit is contained in:
Marcel
2019-01-08 22:42:54 +01:00
parent 56aed78b00
commit 7f887a99b0
67 changed files with 3076 additions and 1755 deletions

View File

@@ -27,7 +27,14 @@
public function getUserNotificationsRaw($userID, $limit = 20, $offset = 0)
{
$this->db->cache_off();
$rawData = $this->db->query('SELECT n.*, count(*) count, s.username senderName, s.displayname senderDisplayname, s.profile_picture senderPicture, r.username recipientName, r.displayName recipientDisplayname FROM notifications n LEFT JOIN users s ON n.senderID = s.ID LEFT JOIN users r ON n.recipientID = r.ID WHERE recipientID = ? GROUP BY type, referenceID ORDER BY createdAt DESC, unread DESC LIMIT ? OFFSET ?', [$userID, $limit, $offset])->result_array();
$rawData = $this->db->query('SELECT n.*, count(*) count, s.username senderName, s.displayname senderDisplayname, ss.profilePicture senderPicture, r.username recipientName, r.displayName recipientDisplayname
FROM notifications n
LEFT JOIN users s ON n.senderID = s.ID
LEFT JOIN user_settings ss ON s.ID = ss.ID
LEFT JOIN users r ON n.recipientID = r.ID
WHERE recipientID = ?
GROUP BY type, referenceID
ORDER BY createdAt DESC, unread DESC LIMIT ? OFFSET ?', [$userID, $limit, $offset])->result_array();
$notifications = [];
foreach ($rawData as $notification) {
@@ -36,7 +43,13 @@
if ($notificationGroup['count'] == 1) {
$notificationGroup['items'] = [$notification];
} else {
$notificationGroup['items'] = $this->db->query('SELECT n.*, s.username senderName, s.displayname senderDisplayname, s.profile_picture senderPicture, r.username recipientName, r.displayName recipientDisplayname FROM notifications n LEFT JOIN users s ON n.senderID = s.ID LEFT JOIN users r ON n.recipientID = r.ID WHERE recipientID = ? AND type = ? AND referenceID = ? LIMIT 5', [$userID, $notification['type'], $notification['referenceID']])->result_array();
$notificationGroup['items'] = $this->db->query('SELECT n.*, s.username senderName, s.displayname senderDisplayname, ss.profilePicture senderPicture, r.username recipientName, r.displayName recipientDisplayname
FROM notifications n
LEFT JOIN users s ON n.senderID = s.ID
LEFT JOIN user_settings ss ON s.ID = ss.ID
LEFT JOIN users r ON n.recipientID = r.ID
WHERE recipientID = ? AND type = ? AND referenceID = ?
LIMIT 5', [$userID, $notification['type'], $notification['referenceID']])->result_array();
}
$notifications[] = $notificationGroup;