-
Notifications
You must be signed in to change notification settings - Fork 0
/
search_rerun.php
executable file
·86 lines (80 loc) · 2.68 KB
/
search_rerun.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/env php
<?php
// This file is part of Music Match.
// Copyright (C) 2022 David P. Anderson
//
// Music Match is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License
// as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Music Match is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See the GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with Music Match. If not, see <http://www.gnu.org/licenses/>.
// --------------------------------------------------------------------
// ops script to rerun searches, record the results, and notify if new results
require_once("../inc/search.inc");
require_once("../inc/boinc_db.inc");
require_once("../inc/forum_db.inc");
function get_nnew($new, $old) {
$n = 0;
foreach ($new as $i) {
if (!in_array($i, $old)) {
$n++;
}
}
return $n;
}
function main() {
$t = time() - 7*86400;
$searches = Search::enum("rerun_time < $t");
foreach ($searches as $search) {
$user = BoincUser::lookup_id($search->user_id);
$params = json_decode($search->params);
$role = $params->role;
$args = add_missing_args($params->args, $role);
switch ($role) {
case COMPOSER:
case PERFORMER:
$results = cp_search($role, $args, $user);
break;
case TECHNICIAN:
$results = tech_search($args, $user);
break;
case ENSEMBLE:
$results = ens_search($args, $user);
break;
case TEACHER:
$results = teacher_search($args, $user);
break;
default:
echo("bad role: $role");
continue;
}
$old_results = json_decode($search->view_results);
$ids = [];
foreach ($results as $id=>$x) {
$ids[] = $id;
}
$nnew = get_nnew($ids, $old_results);
$search->update(
sprintf("rerun_time=%d, rerun_nnew=%d", time(), $nnew)
);
if ($nnew) {
BoincNotify::replace(
sprintf("userid=%d, create_time=%d, type=%d, opaque=0, id2=0, sent_by_email=0",
$user->id, time(), NOTIFY_SEARCH
)
);
}
echo "re-ran search $search->id; got $nnew new results\n";
}
}
echo date(DATE_RFC822), ": Starting\n";
main();
echo date(DATE_RFC822), ": Finished\n";
?>