1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* vipnytt/RobotsTxtParser |
4
|
|
|
* |
5
|
|
|
* @link https://github.com/VIPnytt/RobotsTxtParser |
6
|
|
|
* @license https://github.com/VIPnytt/RobotsTxtParser/blob/master/LICENSE The MIT License (MIT) |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace vipnytt\RobotsTxtParser\Client\Delay\MySQL; |
10
|
|
|
|
11
|
|
|
use vipnytt\RobotsTxtParser\Client\Delay\ManageCore; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Class Manage |
15
|
|
|
* |
16
|
|
|
* @see https://vipnytt.github.io/RobotsTxtParser/methods/DelayInterface.html for documentation |
17
|
|
|
* @package vipnytt\RobotsTxtParser\Handler\Delay\MySQL |
18
|
|
|
*/ |
19
|
|
|
class Manage extends ManageCore |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* Clean the delay table |
23
|
|
|
* |
24
|
|
|
* @return bool |
25
|
|
|
*/ |
26
|
|
View Code Duplication |
public function clean() |
|
|
|
|
27
|
|
|
{ |
28
|
|
|
$delay = self::OUT_OF_SYNC_TIME_LIMIT; |
29
|
|
|
$query = $this->pdo->prepare(<<<SQL |
30
|
|
|
DELETE FROM robotstxt__delay0 |
31
|
|
|
WHERE delayUntil < ((UNIX_TIMESTAMP() - :delay) * 1000000); |
32
|
|
|
SQL |
33
|
|
|
); |
34
|
|
|
$query->bindValue('delay', $delay, \PDO::PARAM_INT); |
35
|
|
|
return $query->execute(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Top X wait time |
40
|
|
|
* |
41
|
|
|
* @param int $limit |
42
|
|
|
* @param int $minDelay |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
|
|
public function getTopWaitTimes($limit = self::TOP_X_LIMIT, $minDelay = self::TOP_X_MIN_DELAY) |
46
|
|
|
{ |
47
|
|
|
$query = $this->pdo->prepare(<<<SQL |
48
|
|
|
SELECT |
49
|
|
|
base, |
50
|
|
|
userAgent, |
51
|
|
|
delayUntil / 1000000 AS delayUntil, |
52
|
|
|
lastDelay / 1000000 AS lastDelay |
53
|
|
|
FROM robotstxt__delay0 |
54
|
|
|
WHERE delayUntil > ((UNIX_TIMESTAMP(CURTIME(6)) + :minDelay) * 1000000) |
55
|
|
|
ORDER BY delayUntil DESC |
56
|
|
|
LIMIT :maxCount; |
57
|
|
|
SQL |
58
|
|
|
); |
59
|
|
|
$query->bindValue('minDelay', $minDelay, \PDO::PARAM_INT); |
60
|
|
|
$query->bindValue('maxCount', $limit, \PDO::PARAM_INT); |
61
|
|
|
$query->execute(); |
62
|
|
|
return $query->fetchAll(\PDO::FETCH_ASSOC); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Base class |
67
|
|
|
* |
68
|
|
|
* @param string $baseUri |
69
|
|
|
* @param string $userAgent |
70
|
|
|
* @param float|int $delay |
71
|
|
|
* @return Base |
72
|
|
|
*/ |
73
|
|
|
public function base($baseUri, $userAgent, $delay) |
74
|
|
|
{ |
75
|
|
|
return new Base($this->pdo, $baseUri, $userAgent, $delay); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.