forked from pouetnet/pouet2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.functions.php
88 lines (79 loc) · 2.37 KB
/
admin.functions.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
87
88
<?
function pouetAdmin_recacheFrontPage()
{
$content = "<ul>";
foreach(glob("cache/*") as $v) { $content .= "<li>deleting '".$v."'</li>\n"; @unlink($v); }
$content .= "</ul>";
return $content;
}
function pouetAdmin_recacheTopDemos()
{
global $timer;
// this needs to be made faster. a LOT faster.
$total = array();
// list by views
$timer["recache_views"]["start"] = microtime_float();
$i=0;
$query="SELECT id,name,views FROM prods ORDER BY views DESC";
$result = SQLLib::Query($query);
$content = "<ol>";
while($tmp = SQLLib::Fetch($result)) {
$total[$tmp->id]+=$i;
$i++;
if ($i<=5)
$content .= "<li><b>"._html($tmp->name)."</b> - ".$tmp->views." views</li>\n";
}
$content .= "</ol>";
$content .= "<h3>".$i." prod views loaded</h3>\n";
$timer["recache_views"]["end"] = microtime_float();
$i=0;
// Get the list of prod IDs ordered by the sum of their comment ratings
$sql = new SQLSelect();
$sql->AddField("prods.id");
$sql->AddField("prods.name");
$sql->AddField("SUM(comments.rating) as theSum");
$sql->AddTable("prods");
$sql->AddJoin("","comments","prods.id = comments.which");
$sql->AddGroup("prods.id");
$sql->AddOrder("SUM(comments.rating) DESC");
$timer["recache_votes"]["start"] = microtime_float();
$result = SQLLib::Query( $sql->GetQuery() );
$content .= "<ol>";
while($tmp = SQLLib::Fetch($result)) {
$total[$tmp->id]+=$i;
$i++;
if ($i<=5)
$content .= "<li><b>"._html($tmp->name)."</b> - "._html($tmp->theSum)." votes</li>\n";
}
$content .= "</ol>";
$content .= "<h3>".$i." vote counts loaded</h3>\n";
$timer["recache_votes"]["end"] = microtime_float();
$timer["recache_sort"]["start"] = microtime_float();
asort($total);
$timer["recache_sort"]["end"] = microtime_float();
$timer["recache_update"]["start"] = microtime_float();
$i=1;
unset($tmp);
unset($top_demos);
$a = array();
while ((list ($key, $val)=each($total)))
{
$a[] = array(
"id" => $key,
"rank" => $i,
);
if (count($a) == 100)
{
SQLLib::UpdateRowMulti("prods","id",$a);
$a = array();
}
$i++;
}
SQLLib::UpdateRowMulti("prods","id",$a);
$content .= "<h3>".$i." prod rankings updated</h3>\n";
$timer["recache_update"]["end"] = microtime_float();
@unlink('cache/pouetbox_topalltime.cache');
@unlink('cache/pouetbox_topmonth.cache');
return $content;
}
?>