This commit is contained in:
@ -1,10 +1,9 @@
|
||||
|
||||
async function query(sql, args) {
|
||||
let rows = [];
|
||||
await ssb.sqlAsync(sql, args ?? [], function(row) {
|
||||
await ssb.sqlAsync(sql, args ?? [], function (row) {
|
||||
rows.push(row);
|
||||
});
|
||||
return rows;;
|
||||
return rows;
|
||||
}
|
||||
|
||||
async function get_biggest() {
|
||||
@ -14,13 +13,16 @@ async function get_biggest() {
|
||||
}
|
||||
|
||||
async function get_total() {
|
||||
return (await query(`
|
||||
return (
|
||||
await query(`
|
||||
select sum(length(content)) as size, count(distinct author) as count from messages;
|
||||
`))[0];
|
||||
`)
|
||||
)[0];
|
||||
}
|
||||
|
||||
async function get_names(identities) {
|
||||
return query(`
|
||||
return query(
|
||||
`
|
||||
SELECT author, name FROM (
|
||||
SELECT
|
||||
messages.author,
|
||||
@ -32,7 +34,9 @@ async function get_names(identities) {
|
||||
json_extract(messages.content, '$.type') = 'about' AND
|
||||
content ->> 'about' = messages.author AND name IS NOT NULL)
|
||||
WHERE author_rank = 1
|
||||
`, [JSON.stringify(identities)]);
|
||||
`,
|
||||
[JSON.stringify(identities)]
|
||||
);
|
||||
}
|
||||
|
||||
async function get_most_follows() {
|
||||
@ -58,22 +62,32 @@ function nice_size(bytes) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
await app.setDocument('<p style="color: #fff">Finding the top 10 largest feeds...</p>');
|
||||
await app.setDocument(
|
||||
'<p style="color: #fff">Finding the top 10 largest feeds...</p>'
|
||||
);
|
||||
let most_follows = await get_most_follows();
|
||||
let total = await get_total();
|
||||
let identities = await ssb.getAllIdentities();
|
||||
let following1 = await ssb.following(identities, 1);
|
||||
let following2 = await ssb.following(identities, 2);
|
||||
let biggest = await get_biggest();
|
||||
let names = await get_names([].concat(biggest.map(x => x.author), most_follows.map(x => x.author)));
|
||||
names = Object.fromEntries(names.map(x => [x.author, x.name]));
|
||||
let names = await get_names(
|
||||
[].concat(
|
||||
biggest.map((x) => x.author),
|
||||
most_follows.map((x) => x.author)
|
||||
)
|
||||
);
|
||||
names = Object.fromEntries(names.map((x) => [x.author, x.name]));
|
||||
for (let item of biggest) {
|
||||
item.name = names[item.author];
|
||||
item.following =
|
||||
identities.indexOf(item.author) != -1 ? 0 :
|
||||
following1[item.author] !== undefined ? 1 :
|
||||
following2[item.author] !== undefined ? 2 :
|
||||
undefined;
|
||||
identities.indexOf(item.author) != -1
|
||||
? 0
|
||||
: following1[item.author] !== undefined
|
||||
? 1
|
||||
: following2[item.author] !== undefined
|
||||
? 2
|
||||
: undefined;
|
||||
}
|
||||
for (let item of most_follows) {
|
||||
item.name = names[item.author];
|
||||
@ -108,4 +122,6 @@ async function main() {
|
||||
await app.setDocument(html);
|
||||
}
|
||||
|
||||
main().catch(function(e) { print(e); });
|
||||
main().catch(function (e) {
|
||||
print(e);
|
||||
});
|
||||
|
Reference in New Issue
Block a user