1 |
|
2 | 'use strict';
|
3 |
|
4 | class RecrawlWarning {
|
5 | constructor(root, count) {
|
6 | this.root = root;
|
7 | this.count = count;
|
8 | }
|
9 |
|
10 | static findByRoot(root) {
|
11 | for (let i = 0; i < this.RECRAWL_WARNINGS.length; i++) {
|
12 | const warning = this.RECRAWL_WARNINGS[i];
|
13 |
|
14 | if (warning.root === root) {
|
15 | return warning;
|
16 | }
|
17 | }
|
18 |
|
19 | return undefined;
|
20 | }
|
21 |
|
22 | static isRecrawlWarningDupe(warningMessage) {
|
23 | if (typeof warningMessage !== 'string') {
|
24 | return false;
|
25 | }
|
26 |
|
27 | const match = warningMessage.match(this.REGEXP);
|
28 |
|
29 | if (!match) {
|
30 | return false;
|
31 | }
|
32 |
|
33 | const count = Number(match[1]);
|
34 | const root = match[2];
|
35 | const warning = this.findByRoot(root);
|
36 |
|
37 | if (warning) {
|
38 |
|
39 |
|
40 | if (warning.count >= count) {
|
41 | return true;
|
42 | } else {
|
43 |
|
44 | warning.count = count;
|
45 | return false;
|
46 | }
|
47 | } else {
|
48 | this.RECRAWL_WARNINGS.push(new RecrawlWarning(root, count));
|
49 | return false;
|
50 | }
|
51 | }
|
52 | }
|
53 |
|
54 | RecrawlWarning.RECRAWL_WARNINGS = [];
|
55 | RecrawlWarning.REGEXP =
|
56 | /Recrawled this watch (\d+) times, most recently because:\n([^:]+)/;
|
57 | module.exports = RecrawlWarning;
|