X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=db.php;h=428c1bf007bb42f85b5551e0633695985dd2ce0d;hb=6be2bf0ba344177f0d1e57d9135bcb97579c54a3;hp=fcf532822a16d35c08885e2069da09a952a06d00;hpb=2c5828c320cc7a3dfd47559dfe1dd1bde76c1b10;p=wfpl.git diff --git a/db.php b/db.php index fcf5328..428c1bf 100644 --- a/db.php +++ b/db.php @@ -276,7 +276,7 @@ function db_get_value($table, $column, $where = '') { $result = db_send_get($table, $column, $where, $args); $value = mysqli_fetch_row($result); - if($value !== false) { + if($value !== NULL) { $value = $value[0]; } @@ -466,10 +466,22 @@ function db_reposition_respace($table, $field, $where = '') { return; } $inc = floor(DB_ORD_MAX / ($c + 1)); - $cur = $inc; - foreach($ids as $id) { - db_update($table, $field, $cur, 'where id=%i', $id); - $cur += $inc; + $ord = $inc; + $count = count($ids); + for ($i = 0; $i < $count; $i += 1000) { + $values = []; + $j_max = min($count, $i + 1000); + for ($j = $i; $j < $j_max; ++$j) { + $id = $ids[$j]; + $values[] = "($id,$ord)"; + $ord += $inc; + } + $sql = + "insert into $table (id,$field) values " + . implode(',', $values) + . " on duplicate key update $field=VALUES($field)" + ; + db_send_query($sql); } } @@ -591,7 +603,7 @@ function db_upgrade() { } if ($version === -1) { - db_send_query('create table if not exists wfpl_mutexes (id int unique auto_increment, name varchar(30) binary, expires int(11)) CHARSET=utf8;'); + db_send_query('create table if not exists wfpl_mutexes (id int unique auto_increment, name varchar(255) binary, expires int(11)) CHARSET=utf8;'); $version = 0; # don't save version now in case another thread is doing this too }