Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚡ sort by real departure and query optimization #2703

Draft
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

MrKrisKrisu
Copy link
Member

@MrKrisKrisu MrKrisKrisu commented Jun 24, 2024

fixes #1382

@MrKrisKrisu MrKrisKrisu changed the title sort by real departure and query optimization ⚡ sort by real departure and query optimization Jun 24, 2024
@MrKrisKrisu MrKrisKrisu marked this pull request as draft June 24, 2024 18:05
@MrKrisKrisu
Copy link
Member Author

Noch nicht ganz fertig... das globale Dashboard sortiert jetzt primär nach Echtzeitdaten, das macht an der Performance durch die letzten DB-Änderungen nichts mehr aus. Den Query hab ich auch so umgeschrieben, dass wir primär Joins nutzen, was die Execution in meinem Fall von 30-40 Sekunden auf nur 40 MILLIsekunden drückt.

Habe gerade nur noch das Problem, dass die Sortierung einen temporary table und filesort macht. Bin aber leider zu sehr MariaDB/MySQL Noob um da gerade eine Lösung parat zu haben... Der Unterschied mit und ohne Sort beträgt 20 Sekunden +-.

t

@MrKrisKrisu
Copy link
Member Author

Das "ALL" bei Users stört mich auch etwas, aber es gibt eigentlich keinen Index mehr der das ändert. Man könnte noch id, private_profile hinzufügen, der ändert aber nichts an der Performance.

@MrKrisKrisu MrKrisKrisu added help wanted Extra attention is needed database labels Jun 24, 2024
@MrKrisKrisu
Copy link
Member Author

SELECT `statuses`.*
FROM   `statuses`
       INNER JOIN `train_checkins`
               ON `train_checkins`.`status_id` = `statuses`.`id`
       INNER JOIN `train_stopovers` AS `origin_stopover`
               ON `train_checkins`.`origin_stopover_id` = `origin_stopover`.`id`
       INNER JOIN `users`
               ON `statuses`.`user_id` = `users`.`id`
       LEFT JOIN `user_mutes`
              ON `user_mutes`.`muted_id` = `users`.`id`
                 AND `user_mutes`.`user_id` = 1
       LEFT JOIN `user_blocks` AS `blocked_users`
              ON `blocked_users`.`blocked_id` = `users`.`id`
                 AND `blocked_users`.`user_id` = 1
       LEFT JOIN `user_blocks` AS `blocked_by_users`
              ON `blocked_by_users`.`user_id` = `users`.`id`
                 AND `blocked_by_users`.`blocked_id` = 1
       LEFT JOIN `follows`
              ON `follows`.`follow_id` = `users`.`id`
                 AND `follows`.`user_id` = 1
WHERE  `user_mutes`.`id` IS NULL
       AND `blocked_users`.`id` IS NULL
       AND `blocked_by_users`.`id` IS NULL
       AND ( ( `users`.`private_profile` = 0
               AND `visibility` IN ( 0, 4 ) )
              OR `users`.`id` = 1
              OR ( `follows`.`id` IS NOT NULL
                   AND `statuses`.`visibility` NOT IN ( 1, 3 ) ) )
       AND `origin_stopover`.`departure_real` < '2024-06-24 23:59'
ORDER  BY `origin_stopover`.`departure_real` DESC,
          `origin_stopover`.`departure_planned` DESC

@HerrLevin
Copy link
Member

Irgendwas stimmt mit der Query aktuell noch nicht. Ich sehe gerade nur meine Check-Ins im (global) dashboard.

Ganz komisch ist auch noch, dass die Tests gerade nicht Alarm schlagen?!

(Aber ansonsten ziemlich nice bis jetzt!)

@HerrLevin
Copy link
Member

HerrLevin commented Jun 26, 2024

Irgendwas stimmt mit der Query aktuell noch nicht. Ich sehe gerade nur meine Check-Ins im (global) dashboard.

Es waren Check-Ins ohne Live-Daten. Fällt im Live-Datensatz seltener auf, aber mit geseedeten Testdaten schon.

@MrKrisKrisu Es bräuchte ne Erweiterung der Tests auf Dashboard mit fehlenden Live-Daten. :)

SELECT `statuses`.*, `origin_stopover`.`departure_real`, `origin_stopover`.`departure_planned`
FROM `statuses`
         INNER JOIN `train_checkins`
                    ON `train_checkins`.`status_id` = `statuses`.`id`
         INNER JOIN `train_stopovers` AS `origin_stopover`
                    ON `train_checkins`.`origin_stopover_id` = `origin_stopover`.`id`
         INNER JOIN `users`
                    ON `statuses`.`user_id` = `users`.`id`
         LEFT JOIN `user_mutes`
                   ON `user_mutes`.`muted_id` = `users`.`id`
                       AND `user_mutes`.`user_id` = 1
                       AND `user_mutes`.`id` IS NULL
         LEFT JOIN `user_blocks` AS `blocked_users`
                   ON `blocked_users`.`blocked_id` = `users`.`id`
                       AND `blocked_users`.`user_id` = 1
                       AND `blocked_users`.`id` IS NULL
         LEFT JOIN `user_blocks` AS `blocked_by_users`
                   ON `blocked_by_users`.`user_id` = `users`.`id`
                       AND `blocked_by_users`.`blocked_id` = 1
                       AND `blocked_by_users`.`id` IS NULL
         LEFT JOIN `follows`
                   ON `follows`.`follow_id` = `users`.`id`
                       AND `follows`.`user_id` = 1
WHERE (
    (`users`.`private_profile` = 0 AND `visibility` IN (0, 4))
        OR `users`.`id` = 1
        OR (`follows`.`id` IS NOT NULL AND `statuses`.`visibility` NOT IN (1, 3)))
  AND (
    `origin_stopover`.`departure_real` < '2024-06-27 23:59'
        OR (
        `origin_stopover`.`departure_real` IS NULL
            AND `origin_stopover`.`departure_planned` < '2024-06-27 23:59')
    )
ORDER BY `origin_stopover`.`departure_real` DESC,
         `origin_stopover`.`departure_planned` 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Checkins with a delay are sorted wrong
2 participants