mirror of
https://github.com/openclassify/openclassify.git
synced 2026-02-09 06:46:08 -06:00
#4803 Ad Model Db Optimization
This commit is contained in:
parent
82028cb8d4
commit
d44896e2a2
@ -287,19 +287,22 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
|||||||
public function getLocationNames($advs)
|
public function getLocationNames($advs)
|
||||||
{
|
{
|
||||||
foreach ($advs as $adv) {
|
foreach ($advs as $adv) {
|
||||||
$country = CountryModel::query()->where('location_countries.id', $adv->country_id)->first();
|
$locale = config('app.locale', config('streams::locales.default'));
|
||||||
$city = CityModel::query()->where('location_cities.id', $adv->city)->first();
|
|
||||||
$district = DistrictModel::query()->where('location_districts.id', $adv->district)->first();
|
|
||||||
|
|
||||||
if ($country != null) {
|
$country_id = $adv->country_id ?? 0;
|
||||||
$adv->setAttribute('country_name', $country->name);
|
$city_id = $adv->city ?? 0;
|
||||||
$adv->setAttribute('country_abv', $country->abv);
|
$district_id = $adv->district ?? 0;
|
||||||
}
|
|
||||||
if ($city != null) {
|
$q = collect(DB::select("
|
||||||
$adv->setAttribute('city_name', $city->name);
|
SELECT country.abv as country_abv, country_trans.name as country_name,
|
||||||
}
|
(SELECT name FROM default_location_cities_translations as city_trans WHERE city_trans.id = " . $city_id . " AND city_trans.locale = '" . $locale . "') as city_name,
|
||||||
if ($district != null) {
|
(SELECT name FROM default_location_districts_translations as district_trans WHERE district_trans.id = " . $district_id . " AND district_trans.locale = '" . $locale . "') as district_name
|
||||||
$adv->setAttribute('district_name', $district->name);
|
FROM default_location_countries AS country
|
||||||
|
JOIN default_location_countries_translations AS country_trans on country.id = country_trans.entry_id WHERE country.id = " . $country_id . " and country_trans.locale = '" . $locale . "'
|
||||||
|
"))->first();
|
||||||
|
|
||||||
|
foreach ($q as $key => $value){
|
||||||
|
$adv->setAttribute($key, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $advs;
|
return $advs;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user