- 1
https://ibb.co/rpFfBMM
Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 4
0
https://ibb.co/rpFfBMM
Просто код не поместится(
+1
SELECT
`1000, 1000000 field`
(SELECT group_concat(band_category_languages.name SEPARATOR ', ')
FROM calendar_entry_categories
LEFT JOIN band_category_languages ON band_category_languages.band_category_id = calendar_entry_categories.band_category_id
WHERE calendar_entry_categories.calendar_entry_id = calendar_entries.id
AND band_category_languages.language_id = 1
GROUP BY calendar_entry_categories.calendar_entry_id) AS band_category_string,
(SELECT entry.id
FROM calendar_entries AS entry
WHERE entry.entry_kind_parent_id = calendar_entries.id
AND entry.profile_type_id = 10869
AND entry.profile_type = 1) AS move_to_personal_calendar,
(SELECT count(moved_entry.id)
FROM calendar_entries AS moved_entry
WHERE moved_entry.entry_kind_parent_id = calendar_entries.id
AND moved_entry.status = 3) AS count_moved,
(SELECT user_images.image
FROM calendar_entries AS calendar_entries1
LEFT JOIN user_images ON user_images.id = calendar_entries1.image
WHERE calendar_entries1.id = calendar_entries.entry_kind_parent_id
AND calendar_entries.entry_kind = 4) AS festival_image,
(SELECT countries1.code
FROM calendar_entries AS calendar_entries1
LEFT JOIN locations AS locations1 ON locations1.id = calendar_entries1.location_id
LEFT JOIN countries AS countries1 ON countries1.id = locations1.country_id
WHERE calendar_entries1.id = calendar_entries.entry_kind_parent_id
AND calendar_entries.entry_kind = 4) AS festival_country_code,
(SELECT count(*)
FROM calendar_entry_likes
WHERE calendar_entry_likes.calendar_entry_id = calendar_entries.id) AS count_of_likes,
(SELECT count(*)
FROM calendar_entry_likes
WHERE calendar_entry_likes.calendar_entry_id = calendar_entries.id
AND calendar_entry_likes.user_id = 10869 ) AS is_like,
(SELECT group_concat(entry_type_languages.name SEPARATOR ', ')
FROM calendar_entry_types
LEFT JOIN entry_type_languages ON entry_type_languages.entry_type_id = calendar_entry_types.entry_type_id
WHERE (calendar_entry_types.calendar_entry_id = calendar_entries.id
OR calendar_entry_types.calendar_entry_id = calendar_entries.entry_kind_parent_id)
AND entry_type_languages.language_id = 1
GROUP BY calendar_entry_types.calendar_entry_id) AS entry_types_string,
(SELECT band_addresses.city_name
FROM band_addresses
WHERE band_addresses.band_id = calendar_entries.profile_type_id) AS band_city_name,
(SELECT countries.code
FROM band_addresses
LEFT JOIN countries ON countries.id = band_addresses.country_id
WHERE band_addresses.band_id = calendar_entries.profile_type_id) AS band_country_code,
(SELECT group_concat(genre_languages.name SEPARATOR ', ')
FROM calendar_entry_genres
LEFT JOIN genre_languages ON genre_languages.genre_id = calendar_entry_genres.genre_id
WHERE calendar_entry_genres.calendar_entry_id = calendar_entries.id
AND genre_languages.language_id = 1
GROUP BY calendar_entry_genres.calendar_entry_id) AS genre_string
FROM `calendar_entries`
LEFT JOIN `locations` ON `locations`.`id` = `calendar_entries`.`location_id`
LEFT JOIN `calendar_entries` AS `festival` ON `festival`.`id` = `calendar_entries`.`entry_kind_parent_id`
LEFT JOIN `locations` AS `festival_location` ON `festival_location`.`id` = (
SELECT calendar_entries1.id
FROM calendar_entries AS calendar_entries1
WHERE calendar_entries1.id = calendar_entries.entry_kind_parent_id
AND calendar_entries.entry_kind = 4
)
LEFT JOIN `countries` ON `countries`.`id` = `locations`.`country_id`
LEFT JOIN `country_languages` ON `country_languages`.`country_id` = `locations`.`country_id`
LEFT JOIN `states` ON `states`.`id` = `locations`.`state_id`
LEFT JOIN `bands` ON `bands`.`id` = `calendar_entries`.`profile_type_id`
AND `bands`.`soft_delete` = 0
AND `bands`.`status` = 1
LEFT JOIN `band_images` ON `band_images`.`id` = `calendar_entries`.`image`
LEFT JOIN `band_privacy_settings` ON `band_privacy_settings`.`band_id` = `calendar_entries`.`profile_type_id`
WHERE (`bands`.`soft_delete` = 0 OR `bands`.`soft_delete` IS NULL)
AND (`bands`.`status` = 1 OR `bands`.`status` IS NULL)
AND ((
(SELECT count(*)
FROM band_administrators
WHERE band_administrators.band_id = bands.id
AND band_administrators.user_id = 10869 ) > ? OR `band_privacy_settings`.`band_privacy_level` != ?
) AND (
(SELECT user_type
FROM users
WHERE users.id = 10869 ) = ? OR `band_privacy_settings`.`band_privacy_level` != ?
) AND (
(SELECT count(*)
FROM user_bands
WHERE user_bands.band_id = bands.id
AND user_bands.status = 1
AND user_bands.user_id = 10869 ) > ? OR `band_privacy_settings`.`band_privacy_level` != ?
) OR `band_privacy_settings`.`band_privacy_level` IS NULL
) AND (`festival`.`entry_kind` = ? OR `festival`.`id` IS NULL)
AND (date(`calendar_entries`.`date_from`) >= ?)
AND `calendar_entries`.`soft_delete` = ?
AND (`country_languages`.`language_id` = ? OR `country_languages`.`language_id` IS NULL)
AND `calendar_entries`.`entry_kind` IN (?, ?)
AND `calendar_entries`.`event_class` IN (?, ?)
AND `calendar_entries`.`status` = ?
GROUP BY `1000, 1000000 field`
ORDER BY calendar_entries.date_from
LIMIT 1000, 20
Сидить замовник такий не тужить тай думку гадає, а що це я буду платити півтори куска спеціалусту за роботу, як є "профі" за 500 доларів, а тут ше і Вася програміст каже, а шо це ти будеш платити таку суму, як я зроблю дешевше за 300! Настрій хороший, угода укладена, робота кипить. Проходить не так багато часу, як замовник каже, а що це сторінка 2хв грузиться, а Вася каже, то нічо ми то все оптимізуємо! Проходить ще декілька місяців, а результату нема. Тоді замовнек розуміє, що Вася не профі і шукає профі в Х рази дорощого! Не так багато часу пройшло, як профі за 1000 каже, я в два рази оптимізував, більше не реально! Замовник пригнічений, шукає профі, і в один прекрасний момент знаходиться дійсно профі, який по домовленості в зарплату X оптимізував, повикидував, переписав, дописав і в результаті 50 мс при 500000 записів. Підсумок: 300 + 1000 + X != 300 :)
+1
$data = [];
$firstGenreId = Genre::where('homepage_filter_band', 1)->first()->id;
$bandSearch = [
'limit' => request('limit') ?? 6,
'genre' => $firstGenreId,
'category' => BandCategory::where('homepage_filter', 1)->first()->id,
'status' => 1
];
$subGenres = Genre::getGenresByCategory($bandSearch['genre']);
$bandSearch['genre'] = [$bandSearch['genre']];
foreach ($subGenres as $subGenre){
array_push($bandSearch['genre'], $subGenre->id);
}
$data['bandsGenre']['bands'] = Band::getBandsLimitListByGenre($bandSearch);
$data['bandsGenre']['filters'] = Genre::isExistGenreByBandFilter();
$data['bandsGenre']['active_filter'] = $firstGenreId;
$data['bandsGenre']['type'] = 'genre';
$data['bandsCategories']['bands'] = Band::getBandsLimitListByCategory($bandSearch);
$data['bandsCategories']['filters'] = BandCategory::isExistCategoryByBandFilter();
$data['bandsCategories']['active_filter'] = $bandSearch['category'];
$data['bandsCategories']['type'] = 'category';
$data['bandsStatus']['bands'] = Band::getBandsLimitListByStatus($bandSearch);
$data['bandsStatus']['active_filter'] = 1;
$data['bandsStatus']['filters'] = (object)[
0 => [
'id' => 1,
'name' => trans('validation-custom.newest')
],
1 => [
'id' => 2,
'name' => trans('validation-custom.lastUpdated')
]
];
$data['bandsStatus']['type'] = 'status';
$firstGenreId = Genre::where('homepage_filter_musician', 1)->first()->id;
$firstInstrumentId = Instrument::where('homepage_filter', 1)->first()->id;
$musicianSearch = [
'limit' => request('limit') ?? 6,
'genre' => $firstGenreId,
'instrument' => $firstInstrumentId,
'status' => 1
];
$subGenres = Genre::getGenresByCategory($musicianSearch['genre']);
$musicianSearch['genre'] = [$musicianSearch['genre']];
foreach ($subGenres as $subGenre){
array_push($musicianSearch['genre'], $subGenre->id);
}
$subInstruments = Instrument::getInstrumentsByCategory($musicianSearch['instrument']);
$musicianSearch['instrument'] = [$musicianSearch['instrument']];
foreach ($subInstruments as $subInstrument){
array_push($musicianSearch['instrument'], $subInstrument->id);
}
$data['musiciansGenre']['musicians'] = User::getMusiciansLimitListByGenre($musicianSearch);
$data['musiciansGenre']['filters'] = Genre::isExistGenreByFilter();
$data['musiciansGenre']['active_filter'] = $firstGenreId;
$data['musiciansGenre']['type'] = 'genre';
$data['musiciansInstrument']['musicians'] = User::getMusiciansLimitListByInstrument($musicianSearch);
$data['musiciansInstrument']['filters'] = Instrument::isExistInstrumentByFilter();
$data['musiciansInstrument']['active_filter'] = $firstInstrumentId;
$data['musiciansInstrument']['type'] = 'instrument';
$data['musiciansStatus']['musicians'] = User::getMusiciansLimitListByStatus($musicianSearch);
$data['musiciansStatus']['active_filter'] = 1;
$data['musiciansStatus']['filters'] = (object)[
0 => [
'id' => 1,
'name' => trans('validation-custom.newest')
],
1 => [
'id' => 2,
'name' => trans('validation-custom.lastUpdated')
]
];
$data['musiciansStatus']['type'] = 'status';
return response()->json($data, 200);
Кажуть - шота сторінка довго грузиться :)
+2
SELECT SQL_NO_CACHE IT.itemCode,
SUBSTRING_INDEX(GROUP_CONCAT(IT.ean),",", 1) as ean,
SUBSTRING_INDEX(GROUP_CONCAT(IT.artCode),",", 1) as artCode,
SUBSTRING_INDEX(GROUP_CONCAT(IT.description),",", 1) as description,
SUBSTRING_INDEX(GROUP_CONCAT(IT.siteName),",", 1) as siteName,
SUBSTRING_INDEX(GROUP_CONCAT(IT.familyName),",", 1) as familyName,
SUBSTRING_INDEX(GROUP_CONCAT(IT.familyCode),",", 1) as familyCode,
SUBSTRING_INDEX(GROUP_CONCAT(IT.SSfamilyCode),",", 1) as SSfamilyCode,
SUBSTRING_INDEX(GROUP_CONCAT(IT.SSfamilyName),",", 1) as SSfamilyName,
SUBSTRING_INDEX(GROUP_CONCAT(IT.sectorCode),",", 1) as sectorCode,
SUBSTRING_INDEX(GROUP_CONCAT(IT.sectorName),",", 1) as sectorName,
SUBSTRING_INDEX(GROUP_CONCAT(IT.radiusCode),",", 1) as radiusCode,
SUBSTRING_INDEX(GROUP_CONCAT(IT.radiusName),",", 1) as radiusName,
FI.areaName,
FI.areaCode,
ROUND(SUM(IT.price), 2) as price,
SUM(IT.quantity) as theoreticalQty,
IFNULL(FI.countedQty, 0) as countedQty,
ROUND(SUM(IT.quantity) * ROUND(SUM(IT.price), 2), 2) as theoreticalQtyValue,
ROUND(IFNULL(FI.countedQty, 0) * ROUND(SUM(IT.price), 2), 2) as countedQtyValue,
IFNULL(FI.countedQty, 0) - SUM(IT.quantity) as stockGapQty,
ROUND((IFNULL(FI.countedQty, 0) - SUM(IT.quantity)) * SUM(IT.price), 2) as stockGapValue,
DATE_FORMAT(ST.lastImport, "%d-%m-%Y %H:%i:%s") as dateOfLastImport,
DATE_FORMAT(NOW(), "%d-%m-%Y %H:%i:%s") as dateOfExport
FROM Items as IT
LEFT JOIN (
SELECT MIN(FI.ean) as ean, SUM(FI.quantity) as countedQty, IT.itemCode,
GROUP_CONCAT(DISTINCT AR.name) as areaName,
GROUP_CONCAT(DISTINCT AR.code) as areaCode
FROM FoundItems as FI
INNER JOIN Items as IT ON FI.ean = IT.ean
LEFT JOIN Areas as AR ON AR.id = FI.areaId
INNER JOIN Stores as ST ON ST.id = IT.storeId
WHERE eventId = ${args.eventId}
AND IT.storeId = (SELECT storeId FROM Events WHERE id = ${args.eventId})
GROUP BY IT.itemCode
) as FI ON IT.itemCode = FI.itemCode
INNER JOIN Stores as ST ON ST.id = IT.storeId
WHERE IT.storeId = (SELECT storeId FROM Events WHERE id = ${args.eventId})
GROUP BY IT.itemCode, FI.areaName, FI.areaCode, FI.countedQty, dateOfLastImport
а що ця конструкція вміє, а ета що, про та ще й ето потрібно впихнути сюди