Оптимизирована работа с короткими урлами - новые урлы в начале ищутся в базе и если такого урла нет, то он добавляется

This commit is contained in:
Krivchikov Dmitry 2016-05-14 13:23:55 +03:00
parent a8733fefbc
commit 79c2a22069
1 changed files with 5 additions and 1 deletions

View File

@ -217,7 +217,11 @@ class IndexController extends Controller
}
$url .= ']';
$shortUrl = ShortUrl::addNew('https://wikipoints.ru'.$url);
$shortUrl = ShortUrl::model()->getAll(array('where' => '`url` LIKE :url', 'limit' => 1), array('url' => $url));
if (!$shortUrl || $shortUrl->isEmpty()) {
$shortUrl = ShortUrl::addNew($url);
}
print 'https://wikipoints.ru/s/'.x62::encode($shortUrl->id);
}