tags.normalized_name

This commit is contained in:
shibafu
2020-07-30 22:42:10 +09:00
parent c7aa002625
commit e2c43fef80
4 changed files with 61 additions and 11 deletions

View File

@@ -4,6 +4,7 @@ namespace App\Console\Commands;
use App\Tag;
use App\Utilities\Formatter;
use DB;
use Illuminate\Console\Command;
class NormalizeTags extends Command
@@ -42,9 +43,19 @@ class NormalizeTags extends Command
*/
public function handle()
{
foreach (Tag::query()->orderBy('name')->cursor() as $tag) {
$normalizedName = $this->formatter->normalizeToSearchIndex($tag->name);
$this->line("{$tag->name} : {$normalizedName}");
}
$start = hrtime(true);
DB::transaction(function () {
/** @var Tag $tag */
foreach (Tag::query()->cursor() as $tag) {
$normalizedName = $this->formatter->normalizeTagName($tag->name);
$this->line("{$tag->name} : {$normalizedName}");
$tag->normalized_name = $normalizedName;
$tag->save();
}
});
$elapsed = (hrtime(true) - $start) / 1e+9;
$this->info("Done! ({$elapsed} sec)");
}
}