Skip to content

Conversation

@nickvergessen
Copy link
Member

@nickvergessen nickvergessen commented Mar 4, 2022

… are combined

Impact

1 query per request

Check the query log after posting a message

Before

SELECT * FROM `oc_appconfig`
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED
SET SESSION AUTOCOMMIT=1
SELECT `uid`, `displayname`, `password` FROM `oc_users` WHERE `uid_lower` = :dcValue1
SELECT * FROM `oc_authtoken` WHERE (`token` = :dcValue1) AND (`version` = :dcValue2)
SELECT `appid`, `configkey`, `configvalue` FROM `oc_preferences` WHERE `userid` = ?
SELECT `class`, `entity`, CAST(`events` AS CHAR) AS `events` FROM `oc_flow_operations` WHERE `events` <> :dcValue1 GROUP BY `class`, `entity`, CAST(`events` AS CHAR)
SELECT `gu`.`gid`, `g`.`displayname` FROM `oc_group_user` `gu` LEFT JOIN `oc_groups` `g` ON `gu`.`gid` = `g`.`gid` WHERE `uid` = :dcValue1
SELECT `gid` FROM `oc_group_admin` WHERE `uid` = :dcValue1 LIMIT 1
SELECT `provider_id`, `enabled` FROM `oc_twofactor_providers` WHERE `uid` = :dcValue1
SELECT `r`.`type`, `r`.`read_only`, `r`.`lobby_state`, `r`.`sip_enabled`, `r`.`assigned_hpb`, `r`.`token`, `r`.`name`, `r`.`description`, `r`.`password`, `r`.`active_guests`, `r`.`active_since`, `r`.`default_permissions`, `r`.`call_permissions`, `r`.`call_flag`, `r`.`last_activity`, `r`.`last_message`, `r`.`lobby_timer`, `r`.`object_type`, `r`.`object_id`, `r`.`listable`, `r`.`remote_server`, `r`.`remote_token`, `r`.`id` AS `r_id`, `a`.`room_id`, `a`.`actor_type`, `a`.`actor_id`, `a`.`display_name`, `a`.`pin`, `a`.`participant_type`, `a`.`favorite`, `a`.`notification_level`, `a`.`notification_calls`, `a`.`last_joined_call`, `a`.`last_read_message`, `a`.`last_mention_message`, `a`.`last_mention_direct`, `a`.`read_privacy`, `a`.`permissions`, `a`.`access_token`, `a`.`remote_id`, `a`.`id` AS `a_id` FROM `oc_talk_rooms` `r` LEFT JOIN `oc_talk_attendees` `a` ON (`a`.`actor_id` = :dcValue2) AND (`a`.`actor_type` = :dcValue3) AND (`a`.`room_id` = `r`.`id`) WHERE `r`.`token` = :dcValue1 LIMIT 1
# Second time is unnecessary here
SELECT `r`.`type`, `r`.`read_only`, `r`.`lobby_state`, `r`.`sip_enabled`, `r`.`assigned_hpb`, `r`.`token`, `r`.`name`, `r`.`description`, `r`.`password`, `r`.`active_guests`, `r`.`active_since`, `r`.`default_permissions`, `r`.`call_permissions`, `r`.`call_flag`, `r`.`last_activity`, `r`.`last_message`, `r`.`lobby_timer`, `r`.`object_type`, `r`.`object_id`, `r`.`listable`, `r`.`remote_server`, `r`.`remote_token`, `r`.`id` AS `r_id`, `a`.`room_id`, `a`.`actor_type`, `a`.`actor_id`, `a`.`display_name`, `a`.`pin`, `a`.`participant_type`, `a`.`favorite`, `a`.`notification_level`, `a`.`notification_calls`, `a`.`last_joined_call`, `a`.`last_read_message`, `a`.`last_mention_message`, `a`.`last_mention_direct`, `a`.`read_privacy`, `a`.`permissions`, `a`.`access_token`, `a`.`remote_id`, `a`.`id` AS `a_id` FROM `oc_talk_rooms` `r` LEFT JOIN `oc_talk_attendees` `a` ON (`a`.`actor_id` = :dcValue2) AND (`a`.`actor_type` = :dcValue3) AND (`a`.`room_id` = `r`.`id`) WHERE `r`.`token` = :dcValue1 LIMIT 1
INSERT INTO `oc_comments` (`parent_id`, `topmost_parent_id`, `children_count`, `actor_type`, `actor_id`, `message`, `verb`, `creation_timestamp`, `latest_child_timestamp`, `object_type`, `object_id`, `reference_id`) VALUES(:dcValue1, :dcValue2, :dcValue3, :dcValue4, :dcValue5, :dcValue6, :dcValue7, :dcValue8, :dcValue9, :dcValue10, :dcValue11, :dcValue12)
UPDATE `oc_talk_rooms` SET `last_message` = :dcValue1, `last_activity` = :dcValue2 WHERE `id` = :dcValue3
SELECT `a`.`room_id`, `a`.`actor_type`, `a`.`actor_id`, `a`.`display_name`, `a`.`pin`, `a`.`participant_type`, `a`.`favorite`, `a`.`notification_level`, `a`.`notification_calls`, `a`.`last_joined_call`, `a`.`last_read_message`, `a`.`last_mention_message`, `a`.`last_mention_direct`, `a`.`read_privacy`, `a`.`permissions`, `a`.`access_token`, `a`.`remote_id`, `a`.`id` AS `a_id`, MAX(`s`.`attendee_id`) AS `attendee_id`, MAX(`s`.`session_id`) AS `session_id`, MAX(`s`.`in_call`) AS `in_call`, MAX(`s`.`last_ping`) AS `last_ping`, MAX(`s`.`id`) AS `s_id` FROM `oc_talk_attendees` `a` LEFT JOIN `oc_talk_sessions` `s` ON `s`.`attendee_id` = `a`.`id` WHERE (`a`.`room_id` = :dcValue1) AND (`a`.`notification_level` = :dcValue2) GROUP BY `a`.`id`
UPDATE `oc_talk_attendees` SET `last_read_message` = :dcValue1 WHERE `id` = :dcValue2
SELECT MIN(`last_read_message`) AS `last_common_read_message` FROM `oc_talk_attendees` WHERE (`actor_type` = :dcValue1) AND (`room_id` = :dcValue2) AND (`read_privacy` = :dcValue3)

After

SELECT * FROM `oc_appconfig`
SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED
SET SESSION AUTOCOMMIT=1
SELECT `uid`, `displayname`, `password` FROM `oc_users` WHERE `uid_lower` = :dcValue1
SELECT * FROM `oc_authtoken` WHERE (`token` = :dcValue1) AND (`version` = :dcValue2)
SELECT `appid`, `configkey`, `configvalue` FROM `oc_preferences` WHERE `userid` = ?
SELECT `class`, `entity`, CAST(`events` AS CHAR) AS `events` FROM `oc_flow_operations` WHERE `events` <> :dcValue1 GROUP BY `class`, `entity`, CAST(`events` AS CHAR)
SELECT `gu`.`gid`, `g`.`displayname` FROM `oc_group_user` `gu` LEFT JOIN `oc_groups` `g` ON `gu`.`gid` = `g`.`gid` WHERE `uid` = :dcValue1
SELECT `gid` FROM `oc_group_admin` WHERE `uid` = :dcValue1 LIMIT 1
SELECT `provider_id`, `enabled` FROM `oc_twofactor_providers` WHERE `uid` = :dcValue1
SELECT `r`.`type`, `r`.`read_only`, `r`.`lobby_state`, `r`.`sip_enabled`, `r`.`assigned_hpb`, `r`.`token`, `r`.`name`, `r`.`description`, `r`.`password`, `r`.`active_guests`, `r`.`active_since`, `r`.`default_permissions`, `r`.`call_permissions`, `r`.`call_flag`, `r`.`last_activity`, `r`.`last_message`, `r`.`lobby_timer`, `r`.`object_type`, `r`.`object_id`, `r`.`listable`, `r`.`remote_server`, `r`.`remote_token`, `r`.`id` AS `r_id`, `a`.`room_id`, `a`.`actor_type`, `a`.`actor_id`, `a`.`display_name`, `a`.`pin`, `a`.`participant_type`, `a`.`favorite`, `a`.`notification_level`, `a`.`notification_calls`, `a`.`last_joined_call`, `a`.`last_read_message`, `a`.`last_mention_message`, `a`.`last_mention_direct`, `a`.`read_privacy`, `a`.`permissions`, `a`.`access_token`, `a`.`remote_id`, `a`.`id` AS `a_id` FROM `oc_talk_rooms` `r` LEFT JOIN `oc_talk_attendees` `a` ON (`a`.`actor_id` = :dcValue2) AND (`a`.`actor_type` = :dcValue3) AND (`a`.`room_id` = `r`.`id`) WHERE `r`.`token` = :dcValue1 LIMIT 1
# No second time here
INSERT INTO `oc_comments` (`parent_id`, `topmost_parent_id`, `children_count`, `actor_type`, `actor_id`, `message`, `verb`, `creation_timestamp`, `latest_child_timestamp`, `object_type`, `object_id`, `reference_id`) VALUES(:dcValue1, :dcValue2, :dcValue3, :dcValue4, :dcValue5, :dcValue6, :dcValue7, :dcValue8, :dcValue9, :dcValue10, :dcValue11, :dcValue12)
UPDATE `oc_talk_rooms` SET `last_message` = :dcValue1, `last_activity` = :dcValue2 WHERE `id` = :dcValue3
SELECT `a`.`room_id`, `a`.`actor_type`, `a`.`actor_id`, `a`.`display_name`, `a`.`pin`, `a`.`participant_type`, `a`.`favorite`, `a`.`notification_level`, `a`.`notification_calls`, `a`.`last_joined_call`, `a`.`last_read_message`, `a`.`last_mention_message`, `a`.`last_mention_direct`, `a`.`read_privacy`, `a`.`permissions`, `a`.`access_token`, `a`.`remote_id`, `a`.`id` AS `a_id`, MAX(`s`.`attendee_id`) AS `attendee_id`, MAX(`s`.`session_id`) AS `session_id`, MAX(`s`.`in_call`) AS `in_call`, MAX(`s`.`last_ping`) AS `last_ping`, MAX(`s`.`id`) AS `s_id` FROM `oc_talk_attendees` `a` LEFT JOIN `oc_talk_sessions` `s` ON `s`.`attendee_id` = `a`.`id` WHERE (`a`.`room_id` = :dcValue1) AND (`a`.`notification_level` = :dcValue2) GROUP BY `a`.`id`
UPDATE `oc_talk_attendees` SET `last_read_message` = :dcValue1 WHERE `id` = :dcValue2
SELECT MIN(`last_read_message`) AS `last_common_read_message` FROM `oc_talk_attendees` WHERE (`actor_type` = :dcValue1) AND (`room_id` = :dcValue2) AND (`read_privacy` = :dcValue3)

@nickvergessen nickvergessen added 3. to review bug feature: chat 💬 Chat and system messages feature: api 🛠️ OCS API for conversations, chats and participants performance 🚀 labels Mar 4, 2022
@nickvergessen nickvergessen added this to the 💛 Next Major (24) milestone Mar 4, 2022
@nickvergessen
Copy link
Member Author

@vitormattos
Copy link
Contributor

vitormattos commented Mar 4, 2022

Excellent the new view mode of GitHub with white spaces hidden

Copy link
Member

@danxuliu danxuliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works 👍

@danxuliu danxuliu merged commit 78b5c3d into master Mar 4, 2022
@danxuliu danxuliu deleted the techdebt/noid/load-room-only-once-on-middleware branch March 4, 2022 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug feature: api 🛠️ OCS API for conversations, chats and participants feature: chat 💬 Chat and system messages performance 🚀

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants