GithubHelp home page GithubHelp logo

tbdev's Issues

Хранение тегов

Вот думаю как хранить теги в базе данных лучше всего, что-б получить быстрый поиск по ним, без использования Sphinx итд.

FULLTEXT - фигня т.к завязка на mySQL
Sphinx - на хостинге не поставишь
LIKE '%tag%' - медленно

Пока-что пришел в такому варианту, но не устраивает план выполнения запроса:

SELECT t.id, t.moderated, t.moderatedby, t.category, t.leechers, t.seeders, t.free,
t.name, t.times_completed, t.size, t.added, t.comments, t.numfiles, t.filename, t.not_sticky,
t.owner, IF(t.numratings < 1, NULL, ROUND(t.ratingsum / t.numratings, 1)) AS rating,
c.name AS cat_name, c.image AS cat_pic, u.username, u.class, EXISTS(
SELECT *
FROM readtorrents
WHERE readtorrents.userid = 1 AND readtorrents.torrentid = t.id) AS readtorrent
FROM torrents AS t
LEFT JOIN categories AS c ON t.category = c.id
LEFT JOIN users AS u ON t.owner = u.id
INNER JOIN tag_index AS ti ON ti.tid = t.id
INNER JOIN tags AS ta ON ta.id = ti.tag
WHERE t.visible = 'yes' AND (ta.name = 'elementary' OR ta.name = '720p')
GROUP BY t.id
ORDER BY t.not_sticky DESC, t.id DESC
LIMIT 0,25

Ну и сами таблицы вот:

CREATE TABLE `tags` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(50) NOT NULL DEFAULT '',
    `count` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0',
    PRIMARY KEY (`id`)
) ENGINE=MyISAM;

INSERT INTO `tags` (`id`, `name`, `count`) VALUES (1, 'elementary', 1);
INSERT INTO `tags` (`id`, `name`, `count`) VALUES (2, 'marvel', 1);
INSERT INTO `tags` (`id`, `name`, `count`) VALUES (3, '720p', 2);

CREATE TABLE `tag_index` (
    `tid` INT(10) UNSIGNED NOT NULL DEFAULT '0',
    `tag` INT(10) UNSIGNED NULL DEFAULT '0',
    UNIQUE INDEX `tagged` (`tid`, `tag`)
) ENGINE=MyISAM;

INSERT INTO `tag_index` (`tid`, `tag`) VALUES (1, 1);
INSERT INTO `tag_index` (`tid`, `tag`) VALUES (1, 3);
INSERT INTO `tag_index` (`tid`, `tag`) VALUES (2, 2);
INSERT INTO `tag_index` (`tid`, `tag`) VALUES (2, 3);

INSERT INTO `torrents` (`id`, `info_hash`, `name`, `filename`, `save_as`, `descr`, `ori_descr`, `image1`, `image2`, `image3`, `image4`, `image5`, `category`, `size`, `added`, `type`, `numfiles`, `comments`, `views`, `hits`, `times_completed`, `leechers`, `seeders`, `last_action`, `last_reseed`, `visible`, `banned`, `owner`, `numratings`, `ratingsum`, `free`, `not_sticky`, `moderated`, `moderatedby`, `keywords`, `description`) VALUES (1, 0x32393761383636333965333862386137393764353336306563663836303164386265363130343638, 'Elementary.S02E14.720p.HDTV.X264-DIMENSION.mkv', 'Elementary.S02E14.720p.HDTV.X264-DIMENSION.mkv.torrent', 'Elementary.S02E14.720p.HDTV.X264-DIMENSION.mkv', 'Elementary S02E14 720p DIMENSION', 'Elementary S02E14 720p DIMENSION', '', '', '', '', '', 11, 887499089, '2014-02-24 14:46:48', 'single', 1, 0, 1, 0, 0, 0, 0, '2014-02-24 14:46:48', '0000-00-00 00:00:00', 'yes', 'no', 1, 0, 0, 'silver', 'yes', 'yes', 1, '', '');
INSERT INTO `torrents` (`id`, `info_hash`, `name`, `filename`, `save_as`, `descr`, `ori_descr`, `image1`, `image2`, `image3`, `image4`, `image5`, `category`, `size`, `added`, `type`, `numfiles`, `comments`, `views`, `hits`, `times_completed`, `leechers`, `seeders`, `last_action`, `last_reseed`, `visible`, `banned`, `owner`, `numratings`, `ratingsum`, `free`, `not_sticky`, `moderated`, `moderatedby`, `keywords`, `description`) VALUES (2, 0x61653536626238323165656239643739366566633934336264383063376661666536616531396366, 'Thor.The.Dark.World.2013.720p.WEB-DL.Rus.Eng.HDCLUB.mkv', 'Thor.The.Dark.World.2013.720p.WEB-DL.Rus.Eng.HDCLUB.mkv.torrent', 'Thor.The.Dark.World.2013.720p.WEB-DL.Rus.Eng.HDCLUB.mkv', 'Thor', 'Thor', '', '', '', '', '', 14, 4099320914, '2014-02-27 12:43:21', 'single', 1, 0, 0, 0, 0, 0, 0, '2014-02-27 12:43:21', '0000-00-00 00:00:00', 'yes', 'no', 1, 0, 0, 'no', 'yes', 'yes', 1, '', '');
+----+--------------------+--------------+--------+----------------------+---------+---------+------------+------+---------------------------------------------------------------------+
| id | select_type        | table        | type   | possible_keys        | key     | key_len | ref        | rows | extra                                                               |
+----+--------------------+--------------+--------+----------------------+---------+---------+------------+------+---------------------------------------------------------------------+
|  1 | PRIMARY            | t            | ref    | PRIMARY,visible,vnsi | visible | 1       | const      | 1    | Using index condition; Using where; Using temporary; Using filesort |
|  1 | PRIMARY            | c            | eq_ref | PRIMARY              | PRIMARY | 4       | t.category | 1    |                                                                     |
|  1 | PRIMARY            | u            | eq_ref | PRIMARY,user         | PRIMARY | 4       | t.owner    | 1    |                                                                     |
|  1 | PRIMARY            | ti           | ref    | tagged               | tagged  | 4       | t.id       | 1    | Using where; Using index                                            |
|  1 | PRIMARY            | ta           | eq_ref | PRIMARY              | PRIMARY | 4       | ti.tag     | 1    | Using where                                                         |
|  2 | DEPENDENT SUBQUERY | readtorrents | eq_ref | read                 | read    | 8       | const,func | 1    | Using where; Using index                                            |
+----+--------------------+--------------+--------+----------------------+---------+---------+------------+------+---------------------------------------------------------------------+

И вот результат, как по мне так ужасен...

У кого какие идеи?

Многопоточное обновление мультитрекера

Сейчас обновление мультитрекера идет в один поток.

А так как таймаут стоит 2 секунды, это пока-что не создает особых проблем.
Если с HTTP трекерами это еще можно решить через curl_multi, то с UDP это, кажется, можно решить только pcntl_fork().

Буду рад pull request на эту тему...

Идея(и)

Смену класса можно же сделать на куках, временную смену класса имеется ввиду.
Как идея?

SphinxQL + announce.php

Кто-то пробовал делать подобное?

/* Tue May 6 15:45:12.517 2014 conn 37669 wall 0.008 found 108 */ SELECT seeder, peer_id, ip, port, resp_compact, uploaded, downloaded, userid, last_action, lastts, nowts, prevts, startts FROM peers WHERE MATCH('@seeder no @torrent_str torrent_18828') LIMIT 0,1000;

Я использую такой запрос в базу данных от аннонсера, для того что-бы получить пиров.
Но иногда залипает - пока не понял где проблема - в сфинксе или в коде аннонсера.

AJAX обновление мультитрекера

Просто необходимо обновлять мультитрекер через AJAX вызов update_multi.php.

Так выглядит намного удобнее и пользователь не покидает страницу.

Сворачивание блоков

Сейчас для установки флага, что блок свертнут используется switch_blocks.php.

Я предлагаю переделать это на плагин jQuery.cookies.
Таким образом будет достигнута большая отзывчивость сайта.

Логичные места для ООП/OOP

ИМХО самое первое место которое стоит переделать на классы это captcha.

$captcha = new Captcha;
$captcha->generate(); // а можно и без этого
echo $captcha->getHtmlForm(); // бежим в View или просто шаблонизатор и получает шаблон для вывода, куда вставляем нужные переменные

if (!$captcha->validate())
    stderr('Error', 'Captcha fail');

Осталось подумать как-же передавать нужный hash от строки, можно как hidden поле в форме.

Дальше идет вывод формы комментариев и сами комментарии:

$comments = new Comments($torrentid, array('type' => 'torrent')); // передать можно ведь и другой вариант, т.е искать будет по другой колонке просто.
$comments->fetch(array('page' => 3, 'pp' => 25)); // или любой другой вариант
echo $comments->getHtml(); // тут уже запрос побежал во вьюуху, забрал шаблон и вывел кусок html.

P.S: Я совсем не желаю использовать такие конструкторы:

$query = SphinxQL::create($ql)->select('id')
    ->from('torrents')
    ->option('ranker', $matcher[$search_type])
    ->limit(1000);
$query->match('descr', SphinxQL::expr(custom_escape_fn($query, $descrsearchstr, $search_type)));

$results = $query->execute();

Буду рад выслушать критику.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.