Upgrade to Pro — share decks privately, control downloads, hide ads and more …

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

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

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

HASEGAWA Tomoki

April 24, 2019
Tweet

More Decks by HASEGAWA Tomoki

Other Decks in Technology

Transcript

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


    αοΧʔ؍ઓ 
 ϨϯλϧΧʔτϨʔε ʜ σδλϧαʔΧεגࣜձࣾ ෭ஂ௕$50 !UPN[PI
  2. 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');
  3. 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');
  4. 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'); είΞͷ߱ॱ
  5. 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'); είΞͷ߱ॱ
  6. 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'); είΞͷ߱ॱ ࠷ऴείΞ֫ಘ࣌ࠁͷঢॱ
  7. 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'); είΞͷ߱ॱ ࠷ऴείΞ֫ಘ࣌ࠁͷঢॱ ಉ఺ͳΒઌʹͦͷ఺਺ʹୡͨ͠ํ͕উͪ
  8. $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; }
  9. $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Λߋ৽ͯ͠Δʜɻ
  10. GPSUFFKQ ϑ Υ ϧ ς wΧϯϑΝϨϯεӡӦࢧԉπʔϧ wεϙϯαʔืू ੥ٻॻ࡞੒ʢ.JTPDB࿈ܞʣ ϩΰड͚औΓ Ұ੪ϝʔ

    ϧ εϙϯαʔҰཡ"1* wϓϩϙʔβϧืूʢ$G1ʣ બఆ λΠϜςʔϒϧΤσΟλ Ұ੪ϝʔϧ  ϓϩϙʔβϧҰཡ"1* λΠϜςʔϒϧදࣔ w4MBDL࿈ܞͯ͠εϙϯαʔԠื΍ϓϩϙʔβϧԠื࣌ʹօͰ੝Γ্͕Δ  wνέοτൢച࣌&WFOUCSJUF࿈ܞͯ͠ࢀՃऀऔΓࠐΈ 5XJUUFSΞΠί ϯऔΓࠐΈ 23ίʔυੜ੒ $47μ΢ϯϩʔυ
 ‎ͦͷ··ҹ࡮԰͞Μʹೖߘͯ͠ΞΠίϯ෇໊͖ࡳ wͦͷଞػೳ͍Ζ͍ΖʢνϟϨϯδػೳ΋͋ΔΑʣ