Bravo List
Register
Go Back   > Bravo List > Source Code > Active Trackers > Torrent Trader
Reply
Thread Tools
  #1  
Old 18th June 2023, 13:39
Extremlym's Avatar
Extremlym Extremlym is offline
Senior Member
 
Join Date: Oct 2012
P2P
Posts: 102
Default Replace query JOIN (help)
hello i wont to replace this LEFT JOIN , i think is loading my database sql , i tryed something but is not working . pls some help



PHP Code:
//Get Total For Pager$res = mysql_query("SELECT COUNT(*) FROM torrents LEFT JOIN categories ON category = categories.id $where") or die(mysql_error());$row = mysql_fetch_array($res);$count = $row[0];//get sql infoif ($count) {    list($pagertop, $pagerbottom, $limit) = pager(35, $count, "torrents.php?" . $addparam);$query = "SELECT torrents.id, torrents.category, ...., torrents.name, torrents.size, torrents.added, torrents.torrentlang, torrents.owner, categories.name AS cat_name, torrentlang.name AS lang_name, torrentlang.image AS lang_image, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy,  IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit" ;        $res = mysql_query($query) or die(mysql_error());}else{    unset($res);} 
Reply With Quote
  #2  
Old 18th June 2023, 13:44
DND DND is offline
VIP
 
Join Date: Dec 2008
Posts: 1,242
Default
when you use joins, make sure to use indexes
__________________
Need HELP!? I can install:

  1. Server/VPS (Debian,CentOS,Ubuntu,Fedora, FreeBSD) Optimization and ... + Modules
  2. Webserver Windows/Linux (Apache/Lighttpd/Nginx/Mysql/PhpMyAdmin/SSL) Optimization and ... + Modules
  3. Seedbox Windows/Linux (uTorrent,rTorrent,libTorrent,ruTorrent) + Modules
  4. Multiple source code engines
  5. Linux Server Administration (security, cryptography/encryption, proxy, load balancer, custom ddos firewall)
Reply With Quote
  #3  
Old 18th June 2023, 14:04
Extremlym's Avatar
Extremlym Extremlym is offline
Senior Member
 
Join Date: Oct 2012
P2P
Posts: 102
Default
Quote:
Originally Posted by DND View Post
when you use joins, make sure to use indexes
CREATE INDEX idx_torrents_category ON torrents (category);
CREATE INDEX idx_torrents_torrentlang ON torrents (torrentlang);
CREATE INDEX idx_torrents_owner ON torrents (owner);


ok let.s see
Reply With Quote
  #4  
Old 18th June 2023, 14:56
Subzero's Avatar
Subzero Subzero is offline
Coder
 
Join Date: Jul 2008
P2P
Posts: 190
Default
If you want to remove the join you could change it to a sub query although if it’s faster or not depends on a lot of factors, the main benefit is it filters out a lot of the data removing much of the overhead but you’d have to run benchmarks to determine if it’s faster in this case.

Example:

PHP Code:
 SELECT COUNT(*) FROM torrents WHERE category IN (SELECT id FROM categories $where
This is just off the cuff so might not work straight out the box I’ve not used torrent trader in a few years.
Reply With Quote
  #5  
Old 18th June 2023, 16:33
Extremlym's Avatar
Extremlym Extremlym is offline
Senior Member
 
Join Date: Oct 2012
P2P
Posts: 102
Default
sql structure

PHP Code:
CREATE TABLE IF NOT EXISTS `torrents` (  `idint(10unsigned NOT NULL,  `info_hashvarchar(100CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,  `namevarchar(255CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',  `filenamevarchar(255CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT '',  `save_asvarchar(255CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',  `search_texttext CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `descrtext CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,  `ori_descrtext CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `categoryint(10unsigned NOT NULL DEFAULT 0,  `sizebigint(20unsigned NOT NULL DEFAULT 0,  `addeddatetime NOT NULL DEFAULT '2000-01-01 01:01:01',  `typeenum('single','multi'CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT 'single',  `numfilesint(10unsigned NOT NULL DEFAULT 0,  `commentsint(10unsigned NOT NULL DEFAULT 0,  `viewsint(10unsigned NOT NULL DEFAULT 0,  `hitsint(10unsigned NOT NULL DEFAULT 0,  `times_completedint(10unsigned NOT NULL DEFAULT 0,  `leechersint(10unsigned NOT NULL DEFAULT 5,  `seedersint(10unsigned NOT NULL DEFAULT 10,  `last_actiondatetime NOT NULL DEFAULT '2000-01-01 01:01:01',  `visibleenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'yes',  `bannedenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `ownerint(10unsigned NOT NULL DEFAULT 0,  `numratingsint(10unsigned NOT NULL DEFAULT 0,  `ratingsumint(10unsigned NOT NULL DEFAULT 0,  `nfotext CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,  `freeenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT 'no',  `smalldvarchar(255CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `recommendedenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `postervarchar(255CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `bgsubsenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `bgaudioenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `genrevarchar(40CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `genre1varchar(40CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `genre2varchar(40CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `stickyenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `pretimedatetime NOT NULL DEFAULT '2000-01-01 01:01:01',  `afterpretext CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,  `urlvarchar(80CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,  `double_uploadenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `seenblob NOT NULL,  `subsvarchar(100CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '',  `externalblob NOT NULL,  `x2enum('yes','no'CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT 'no',  `descriptionvarchar(120CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '',  `anonenum('yes','no'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `announcevarchar(255CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '',  `image1text CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `image2text CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL,  `torrentlangint(10unsigned NOT NULL DEFAULT 1,  `torrentint(10unsigned NOT NULL,  `pathvarchar(255CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,  `filesizeint(10unsigned NOT NULL,  `tubevarchar(80CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '',  `updatedenum('0','1'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '0',  `imdbvarchar(125CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,  `addbookmarkchar(3CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT 'no',  `thankslongtext CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,  `pointsint(10NOT NULL DEFAULT 0,  `freeleechenum('0','1'CHARACTER SET latin1 COLLATE latin1_swedish_ci NOT NULL DEFAULT '1',  `trailersvarchar(255CHARACTER SET latin1 COLLATE latin1_swedish_ci DEFAULT NULL,  `viptorrentstext CHARACTER SET utf8 COLLATE utf8_general_ci DEFAULT NULL,  `recommendedxenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `topenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `likesint(10unsigned NOT NULL DEFAULT 0,  `loveint(10unsigned NOT NULL DEFAULT 0,  `dislikeint(10unsigned NOT NULL DEFAULT 0,  `angryint(10unsigned NOT NULL DEFAULT 0,  `wowint(10unsigned NOT NULL DEFAULT 0,  `rosubbedenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `hardcodedenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `italiansubenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `dublatroenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `dubbedenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `multilangenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `remuxenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `HDRenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `3denum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `flacdstenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `adsonenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `VRenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `frenchsubenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `russiansubenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `engsubenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `germansubenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `4khdrenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `UHDenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `fhdenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `SDenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `KoreanHCenum('yes','no'CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL DEFAULT 'no',  `tmdbvarchar(125CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULLENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;---- Indexes for dumped tables------ Indexes for table `torrents`--ALTER TABLE `torrents`  ADD PRIMARY KEY (`id`) USING BTREE,  ADD UNIQUE KEY `info_hash` (`info_hash`),  ADD KEY `owner` (`owner`),  ADD KEY `visible` (`visible`),  ADD KEY `category_visible` (`category`,`visible`) USING BTREE,  ADD KEY `id` (`id`),  ADD KEY `id_2` (`id`),  ADD KEY `category` (`category`),  ADD KEY `idx_torrents_category` (`category`),  ADD KEY `idx_torrents_torrentlang` (`torrentlang`),  ADD KEY `idx_torrents_owner` (`owner`),  ADD FULLTEXT KEY `ft_search` (`search_text`,`ori_descr`);ALTER TABLE `torrents`  ADD FULLTEXT KEY `name` (`name`);---- AUTO_INCREMENT for dumped tables------ AUTO_INCREMENT for table `torrents`--ALTER TABLE `torrents`  MODIFY `idint(10unsigned NOT NULL AUTO_INCREMENT;/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */
how can i add force index in this
Quote:
//Get Total For Pager$res = mysql_query("SELECT COUNT(*) FROM torrents LEFT JOIN categories ON category = categories.id $where") or die(mysql_error());$row = mysql_fetch_array($res);$count = $row[0];//get sql infoif ($count) { list($pagertop, $pagerbottom, $limit) = pager(35, $count, "torrents.php?" . $addparam);$query = "SELECT torrents.id, torrents.category, ...., torrents.name, torrents.size, torrents.added, torrents.torrentlang, torrents.owner, categories.name AS cat_name, torrentlang.name AS lang_name, torrentlang.image AS lang_image, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy, IF(torrents.numratings < 2, NULL, ROUND(torrents.ratingsum / torrents.numratings, 1)) AS rating FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit" ; $res = mysql_query($query) or die(mysql_error());}else{ unset($res);}

Last edited by Extremlym; 18th June 2023 at 19:38.
Reply With Quote
  #6  
Old 19th June 2023, 00:28
mogo mogo is offline
Senior Member
 
Join Date: Jun 2020
P2P
Posts: 97
Default
Hello, first of all what is your version of TT that you are using mysql_query and not mysqli or SQL_Query_exec I dont understand???
Reply With Quote
  #7  
Old 24th June 2023, 12:05
Extremlym's Avatar
Extremlym Extremlym is offline
Senior Member
 
Join Date: Oct 2012
P2P
Posts: 102
Default
I FOUND THE SOLUTION!
the problem was from CLEANUP.php


just disable this line



//OPTIMIZE TABLES

//$res = mysql_query("SHOW TABLES");

//while ( $table = mysql_fetch_row($res) )
//{
// Get rid of overhead.
// mysql_query("REPAIR TABLE `$table[0]`;");
// Analyze table for faster indexing.
// mysql_query("ANALYZE TABLE `$table[0]`;");
// Optimize table to minimize thrashing.
// mysql_query("OPTIMIZE TABLE `$table[0]`;");
//

Bump:
Quote:
Originally Posted by Subzero View Post
If you want to remove the join you could change it to a sub query although if it’s faster or not depends on a lot of factors, the main benefit is it filters out a lot of the data removing much of the overhead but you’d have to run benchmarks to determine if it’s faster in this case.

Example:

PHP Code:
 SELECT COUNT(*) FROM torrents WHERE category IN (SELECT id FROM categories $where
This is just off the cuff so might not work straight out the box I’ve not used torrent trader in a few years.

need a soliution i have 2.45m torrents and page is loading verry slow

PHP Code:
//Get Total For Pager$res = mysql_query("SELECT COUNT(*) FROM torrents LEFT JOIN categories ON category = categories.id $where LIMIT 35 ") or die(mysql_error());$row = mysql_fetch_array($res);$count = $row[0];//get sql infoif ($count) {    list($pagertop, $pagerbottom, $limit) = pager(35, $count, "torrents.php?" . $addparam);$query = "SELECT torrents.id, torrents.category, torrents.sticky, torrents.recommendedx, torrents.viptorrents, torrents.rosubbed, torrents.hardcoded, torrents.italiansub, torrents.dublatro, torrents.dubbed, torrents.multilang, torrents.remux, torrents.HDR, torrents.3d, torrents.flacdst, torrents.adson, torrents.VR, torrents.frenchsub, torrents.russiansub, torrents.engsub, torrents.germansub, torrents.4khdr, torrents.UHD, torrents.fhd, torrents.SD, torrents.KoreanHC, torrents.description, torrents.leechers, torrents.seeders, torrents.name, torrents.size, torrents.torrentlang, torrents.owner, categories.name AS cat_name, torrentlang.name AS lang_name, torrentlang.image AS lang_image, categories.parent_cat AS cat_parent, categories.image AS cat_pic, users.username, users.privacy FROM torrents LEFT JOIN categories ON category = categories.id LEFT JOIN torrentlang ON torrents.torrentlang = torrentlang.id LEFT JOIN users ON torrents.owner = users.id $where $orderby $limit";    $res = mysql_query($query) or die(mysql_error());}else{    unset($res);} 
</div>

need to limit this $query from total to last 10k
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT +2. The time now is 00:15. vBulletin skin by ForumMonkeys. Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.