Changeset 1112 for trunk


Ignore:
Timestamp:
03/19/10 20:25:22 (2 years ago)
Author:
bogdan2412
Message:

Fix some issues with the migrate-ia-score script.

  • Strings were latin1 instead of utf8 and it caused queries to run

super slow when viewing round tasks.

  • There were no primary keys for the tables
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/scripts/migrate-ia-score.php

    r1110 r1112  
    77 
    88    $query = "CREATE TABLE `ia_score_user_round` ( 
    9                 user_id int, 
    10                 round_id varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci, 
    11                 score decimal(11, 4), 
    12                 CONSTRAINT user_round UNIQUE (user_id, round_id) 
     9                user_id int NOT NULL, 
     10                round_id varchar(64) CHARACTER SET utf8 NOT NULL, 
     11                score decimal(11, 4) NOT NULL, 
     12                PRIMARY KEY user_round (user_id, round_id) 
    1313                )"; 
    1414    db_query($query); 
    1515 
    1616    $query = "CREATE TABLE `ia_score_user_round_task` ( 
    17                 user_id int, 
    18                 round_id varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci, 
    19                 task_id varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci, 
    20                 score decimal(11, 4), 
    21                 CONSTRAINT user_round_task UNIQUE (user_id, round_id, task_id) 
     17                user_id int NOT NULL, 
     18                round_id varchar(64) CHARACTER SET utf8 NOT NULL, 
     19                task_id varchar(64) CHARACTER SET utf8 NOT NULL, 
     20                score decimal(11, 4) NOT NULL, 
     21                PRIMARY KEY user_round_task (user_id, round_id, task_id) 
    2222                )"; 
    2323    db_query($query); 
    2424 
    2525    $query = "CREATE TABLE `ia_rating` ( 
    26                 user_id int, 
    27                 round_id varchar(64) CHARACTER SET latin1 COLLATE latin1_general_ci, 
    28                 deviation decimal(11, 4), 
    29                 rating decimal(11, 4), 
    30                 CONSTRAINT user_round UNIQUE (user_id, round_id) 
     26                user_id int NOT NULL, 
     27                round_id varchar(64) CHARACTER SET utf8 NOT NULL, 
     28                deviation decimal(11, 4) NOT NULL, 
     29                rating decimal(11, 4) NOT NULL, 
     30                PRIMARY KEY user_round (user_id, round_id) 
    3131                )"; 
    3232    db_query($query); 
     
    4646                 db_query($query); 
    4747            } 
    48   
     48 
    4949            $query = "UPDATE `ia_rating` SET `".$score['name']."` = ".db_quote($score['score'])." WHERE ".$where; 
    5050            db_query($query); 
    5151        } else if ($score['name'] == 'score') { 
     52            if (is_null($score["round_id"])) { 
     53                echo implode(' | ', $score)." dumped\n"; 
     54                continue; 
     55            } 
    5256            $query = "INSERT INTO `ia_score_user_round_task` (`user_id`, `round_id`, `task_id`, `score`) 
    5357                        VALUES (".implode(',', 
    5458                            array( 
    5559                                db_quote($score['user_id']), 
    56                                 db_quote($score['round_id']),  
     60                                db_quote($score['round_id']), 
    5761                                db_quote($score['task_id']), 
    5862                                db_quote($score['score'])) 
     
    8084            } 
    8185            db_query($query); 
    82         } else echo implode(' | ', $score)." dumped\n"; 
     86        } else if ($score["name"] == "submit_count") { 
     87            // submit_count is useless and can be ignored 
     88        } else { 
     89            echo implode(' | ', $score)." dumped\n"; 
     90        } 
    8391    } 
    8492 
     
    8694    $rounds = db_fetch_all($query); 
    8795 
    88 //    $query = "DROP TABLE `ia_score`"; 
    89 //    db_query($query) 
     96    $query = "DROP TABLE `ia_score`"; 
     97    db_query($query) 
    9098?> 
Note: See TracChangeset for help on using the changeset viewer.