ranking schmanking
This commit is contained in:
parent
3074b0294a
commit
e2f15ce862
@ -118,46 +118,5 @@ export default (router, tpl) => {
|
||||
res.redirect(`/${referer}`);
|
||||
});
|
||||
|
||||
router.get(/^\/ranking$/, async (req, res) => {
|
||||
try {
|
||||
const list = await db`
|
||||
select
|
||||
"user".user,
|
||||
coalesce("user_options".avatar, ${await lib.getDefaultAvatar()}) as avatar,
|
||||
count(distinct(tag_id, item_id)) as count
|
||||
from "tags_assign"
|
||||
left join "user" on "user".id = "tags_assign".user_id
|
||||
left join "user_options" on "user_options".user_id = "user".id
|
||||
group by "user".user, "user_options".avatar
|
||||
order by count desc
|
||||
`;
|
||||
const stats = await lib.countf0cks();
|
||||
|
||||
const hoster = await db`
|
||||
with t as (
|
||||
select
|
||||
split_part(substring(src, position('//' in src)+2), '/', 1) part
|
||||
from items
|
||||
)
|
||||
select t.part, count(t.part) as c
|
||||
from t
|
||||
group by t.part
|
||||
order by c desc
|
||||
limit 20
|
||||
`;
|
||||
|
||||
res.reply({
|
||||
body: tpl.render('ranking', {
|
||||
list,
|
||||
stats,
|
||||
hoster,
|
||||
tmp: null
|
||||
}, req)
|
||||
});
|
||||
} catch(err) {
|
||||
res.end(JSON.stringify(err.message));
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
||||
|
57
src/inc/routes/ranking.mjs
Normal file
57
src/inc/routes/ranking.mjs
Normal file
@ -0,0 +1,57 @@
|
||||
import db from "../../inc/sql.mjs";
|
||||
import lib from "../lib.mjs";
|
||||
|
||||
export default (router, tpl) => {
|
||||
router.get(/^\/ranking$/, async (req, res) => {
|
||||
try {
|
||||
const list = await db`
|
||||
select
|
||||
"user".user,
|
||||
coalesce("user_options".avatar, ${await lib.getDefaultAvatar()}) as avatar,
|
||||
count(distinct(tag_id, item_id)) as count
|
||||
from "tags_assign"
|
||||
left join "user" on "user".id = "tags_assign".user_id
|
||||
left join "user_options" on "user_options".user_id = "user".id
|
||||
group by "user".user, "user_options".avatar
|
||||
order by count desc
|
||||
`;
|
||||
const stats = await lib.countf0cks();
|
||||
|
||||
const hoster = await db`
|
||||
with t as (
|
||||
select
|
||||
split_part(substring(src, position('//' in src)+2), '/', 1) part
|
||||
from items
|
||||
)
|
||||
select t.part, count(t.part) as c
|
||||
from t
|
||||
group by t.part
|
||||
order by c desc
|
||||
limit 20
|
||||
`;
|
||||
|
||||
const favotop = await db`
|
||||
select item_id, count(*) favs
|
||||
from favorites
|
||||
group by item_id
|
||||
having count(*) > 1
|
||||
order by favs desc
|
||||
limit 10
|
||||
`;
|
||||
|
||||
res.reply({
|
||||
body: tpl.render('ranking', {
|
||||
list,
|
||||
stats,
|
||||
hoster,
|
||||
favotop,
|
||||
tmp: null
|
||||
}, req)
|
||||
});
|
||||
} catch(err) {
|
||||
res.end(JSON.stringify(err.message));
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
@ -38,6 +38,13 @@
|
||||
<tr><td>deleted</td><td>{{ stats.deleted }}</td></tr>
|
||||
<tr><td>missing ids</td><td>{{ stats.untracked }}</td></tr>
|
||||
</table>
|
||||
|
||||
<h3>Top f0cks</h3>
|
||||
<table class="table">
|
||||
@each(favotop as favo)
|
||||
<tr><td><a href="/{{ favo.item_id }}">{{ favo.item_id }}</a></td><td>{{ favo.favs }}</td></tr>
|
||||
@endeach
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user