-
Notifications
You must be signed in to change notification settings - Fork 5
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
feat(pages): patrons page #317
Conversation
Je review vendredi 👀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Manque des specs. (Ça aurait chopé l'erreur du LN(4)
par exemple).
app/controllers/pages_controller.rb
Outdated
@users = User | ||
.select("users.uid AS uid, users.username AS username, COUNT(referees.id) AS referrals") | ||
.select("CASE WHEN COUNT(referees.id) > 0 THEN CEIL(100 * LN(4)) ELSE 0 END AS aura") | ||
.joins("LEFT JOIN users referees ON users.id = referees.referrer_id") | ||
.group("users.id") | ||
.order(aura: :desc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
La logique de calcul de l'aura n'a pas sa place dans le controller. Plutôt à mettre dans une classe dédiée, ou au pire dans le modèle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Aquaj Je suis en train de reflechir a la remarque que tu fais et je comprend mais j'ai pas d'idée sur comment appliquer ca d'une meilleure facon sans perdre en performance.
La ce que la query me permet de faire c'est récupéré, en une seule query SQL, tous les Users, avec le nombre de referees qu'ils ont, et leur aura.
SELECT
users.uid AS uid,
users.username AS username,
COUNT(referees.id) AS referrals,
CASE WHEN COUNT(referees.id) > 0 THEN CEIL(100 * LN(COUNT(referees.id) + 1)) ELSE 0 END AS aura
FROM "users"
LEFT JOIN users referees ON users.id = referees.referrer_id
GROUP BY "users"."id"
ORDER BY "aura" DESC
J'ai l'impression que isolé le calcul de l'aura va nous forcer a répéter plusieurs queries au leiu d'en avoir qu'une seule comme ici.
Avec plus de 1000 users queried a chaques fois on a un besoin de faire au plus performant sur cette requete je penses, et donc de la maintenant en un bloque comme ici
@Aquaj C'est pour ca qu'on fait (100 * Math.log(1 + referrals, Math::E)).ceil Comme ca si tu as 1 referee alors tu as |
Tout à fait. Elle manque juste à l'implem SQL en place. En allant revoir l'issue j'ai vu que le |
1f0d6f2
to
381265e
Compare
5c7264c
to
d9b1b2f
Compare
Summary of changes and context
closes #304
Can probably be refactored a bit but I'm proud of that one query to get everything 👀
A
User::aura
method has been added to the model in case we wanna access the aura somewhere else at some pointI made it a class method because the
#order(aura: :desc)
in the afore mentioned Active::Record query would call theUser#aura
instead of theSELECT aura
otherwise for some reason 🤔I've trying doing
#order("aura DESC")
but it was doing the same.The introduction text for the
/patrons
page is missing atm, waiting for @pil0uSanity checks