ランキング実装に失敗するとこうなるという例 / Broken ranking

ランキング実装に失敗するとこうなるという例 / Broken ranking

PHP勉強会@東京 #134 の資料です。

40575ebf9c2f4a6e3bcb68630f446a3b?s=128

HASEGAWA Tomoki

April 24, 2019
Tweet

Transcript

  1. ௕୩઒ஐر ϥϯΩϯά࣮૷ʹ ࣦഊ͢Δͱ͜͏ͳΔͱ͍͏ྫ

  2. ௕୩઒ஐر !UPN[PI

  3. ϥΠϑϫʔΫ ςοΫΧϯϑΝϨϯεӡӦࢀՃ  8FCJ04ΞϓϦ։ൃ Ϗʔϧ  $16 ϨτϩήʔϜػ ిࢠ޻࡞ 


    αοΧʔ؍ઓ 
 ϨϯλϧΧʔτϨʔε ʜ σδλϧαʔΧεגࣜձࣾ ෭ஂ௕$50 !UPN[PI
  4. None
  5. None
  6. 8FC%FWFMPQNFOUXJUI 8&"3&)*3*/( IUUQXXXEHDJSDVTDPN 0NPUFTBOEP 5PLZP

  7. ࢿྉެ։ࡁͰ͢ !UPN[PI

  8. ࠓ೔ͷςʔϚ

  9. None
  10. ϥϯΩϯά࣮૷ʹ ࣦഊ͢Δͱ͜͏ͳΔͱ͍͏ྫ

  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. SELECT tmp.attendee_id, tmp.score, tmp.rank FROM ( select attendee_id, score, @c:=@c+1

    rank from challenge_players where conference_id = :conference_id and challenge_id = :challenge_id order by score desc, last_scored asc ) tmp ', [ 'conference_id' => $challenge->conference_id, 'challenge_id' => $challenge->id, ]) ->fetchAll('assoc');
  18. SELECT tmp.attendee_id, tmp.score, tmp.rank FROM ( select attendee_id, score, @c:=@c+1

    rank from challenge_players where conference_id = :conference_id and challenge_id = :challenge_id order by score desc, last_scored asc ) tmp ', [ 'conference_id' => $challenge->conference_id, 'challenge_id' => $challenge->id, ]) ->fetchAll('assoc');
  19. SELECT tmp.attendee_id, tmp.score, tmp.rank FROM ( select attendee_id, score, @c:=@c+1

    rank from challenge_players where conference_id = :conference_id and challenge_id = :challenge_id order by score desc, last_scored asc ) tmp ', [ 'conference_id' => $challenge->conference_id, 'challenge_id' => $challenge->id, ]) ->fetchAll('assoc'); είΞͷ߱ॱ
  20. SELECT tmp.attendee_id, tmp.score, tmp.rank FROM ( select attendee_id, score, @c:=@c+1

    rank from challenge_players where conference_id = :conference_id and challenge_id = :challenge_id order by score desc, last_scored asc ) tmp ', [ 'conference_id' => $challenge->conference_id, 'challenge_id' => $challenge->id, ]) ->fetchAll('assoc'); είΞͷ߱ॱ
  21. SELECT tmp.attendee_id, tmp.score, tmp.rank FROM ( select attendee_id, score, @c:=@c+1

    rank from challenge_players where conference_id = :conference_id and challenge_id = :challenge_id order by score desc, last_scored asc ) tmp ', [ 'conference_id' => $challenge->conference_id, 'challenge_id' => $challenge->id, ]) ->fetchAll('assoc'); είΞͷ߱ॱ ࠷ऴείΞ֫ಘ࣌ࠁͷঢॱ
  22. SELECT tmp.attendee_id, tmp.score, tmp.rank FROM ( select attendee_id, score, @c:=@c+1

    rank from challenge_players where conference_id = :conference_id and challenge_id = :challenge_id order by score desc, last_scored asc ) tmp ', [ 'conference_id' => $challenge->conference_id, 'challenge_id' => $challenge->id, ]) ->fetchAll('assoc'); είΞͷ߱ॱ ࠷ऴείΞ֫ಘ࣌ࠁͷঢॱ ಉ఺ͳΒઌʹͦͷ఺਺ʹୡͨ͠ํ͕উͪ
  23. None
  24. ͜ΕͰ ఺ʹͳͬͨ

  25. ͜ΕͰ ఺ʹͳͬͨ ͜ΕͰ ఺ʹ௥͍෇͍ͨ

  26. $challengeInputsQuery = TableRegistry::get('ChallengeInputs')->find() ->where([ 'conference_id' => $challengePlayer->conference_id, 'challenge_id' => $challengePlayer->challenge_id,

    'attendee_id' => $challengePlayer->attendee_id, ]); $scoreTotal = $challengeInputsQuery ->select([ 'score_total' => $challengeInputsQuery->func()->sum('score') ]) ->first(); if (! is_null($scoreTotal->score_total)){ $challengePlayer->score = intval($scoreTotal->score_total); $challengePlayer->last_scored = new Time(); } else { $challengePlayer->score = 0; }
  27. $challengeInputsQuery = TableRegistry::get('ChallengeInputs')->find() ->where([ 'conference_id' => $challengePlayer->conference_id, 'challenge_id' => $challengePlayer->challenge_id,

    'attendee_id' => $challengePlayer->attendee_id, ]); $scoreTotal = $challengeInputsQuery ->select([ 'score_total' => $challengeInputsQuery->func()->sum('score') ]) ->first(); if (! is_null($scoreTotal->score_total)){ $challengePlayer->score = intval($scoreTotal->score_total); $challengePlayer->last_scored = new Time(); } else { $challengePlayer->score = 0; } ਖ਼ղτʔΫϯ͡Όͳͯ͘΋ MBTU@TDPSFEΛߋ৽ͯ͠Δʜɻ
  28. None
  29. ແ೦

  30. ·ͱΊ

  31. wϥϯΩϯά͸είΞτʔλϧΛϨίʔυʹ
 ॻ͍͓͚ͯ͹ൺֱత؆୯ʹ࡞ΕΔΑɻ ·ͱΊ

  32. wϥϯΩϯά͸είΞτʔλϧΛϨίʔυʹ
 ॻ͍͓͚ͯ͹ൺֱత؆୯ʹ࡞ΕΔΑɻ wಉ఺͕ൃੜͨ࣌͠ͷϩδοΫΛॻ͘ͳΒςετ΋
 ͠Α͏Ͷɻ ·ͱΊ

  33. wϥϯΩϯά͸είΞτʔλϧΛϨίʔυʹ
 ॻ͍͓͚ͯ͹ൺֱత؆୯ʹ࡞ΕΔΑɻ wಉ఺͕ൃੜͨ࣌͠ͷϩδοΫΛॻ͘ͳΒςετ΋
 ͠Α͏Ͷɻ w·͋੝Γ্͕͍͍͔ͬͨ͠ɻʢࢮʣ ·ͱΊ

  34. ͓ΘΓ !UPN[PI ͓ΘΓ

  35. ༨ஊ

  36. None
  37. 

  38. 

  39. None
  40. GPSUFFKQ ϑ Υ ϧ ς wΧϯϑΝϨϯεӡӦࢧԉπʔϧ wεϙϯαʔืू ੥ٻॻ࡞੒ʢ.JTPDB࿈ܞʣ ϩΰड͚औΓ Ұ੪ϝʔ

    ϧ εϙϯαʔҰཡ"1* wϓϩϙʔβϧืूʢ$G1ʣ બఆ λΠϜςʔϒϧΤσΟλ Ұ੪ϝʔϧ  ϓϩϙʔβϧҰཡ"1* λΠϜςʔϒϧදࣔ w4MBDL࿈ܞͯ͠εϙϯαʔԠื΍ϓϩϙʔβϧԠื࣌ʹօͰ੝Γ্͕Δ  wνέοτൢച࣌&WFOUCSJUF࿈ܞͯ͠ࢀՃऀऔΓࠐΈ 5XJUUFSΞΠί ϯऔΓࠐΈ 23ίʔυੜ੒ $47μ΢ϯϩʔυ
 ‎ͦͷ··ҹ࡮԰͞Μʹೖߘͯ͠ΞΠίϯ෇໊͖ࡳ wͦͷଞػೳ͍Ζ͍ΖʢνϟϨϯδػೳ΋͋ΔΑʣ
  41. GPSUFFKQ ϑ Υ ϧ ς wЌӡ༻த w·ͩ࢖͍ʹ͔ͬͨ͘Γ෼͔Γʹ͍͘ͱ͜Ζ΋͋Δ wόά͸େ෼ͳ͘ͳͬͨ w௕୩઒ͷ஌Γ߹͍ͷํͰ͋Ε͹ൺֱత
 ҆৺ͯ͠࢖͑ΔͷͰ͸


    
 ͝૬ஊ͍ͩ͘͞