forked from cory/tildefriends
storage: Show accounts with the most follows, for help pruning accounts.
This commit is contained in:
parent
4c2fa2c1b3
commit
740d788c7c
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"type": "tildefriends-app",
|
"type": "tildefriends-app",
|
||||||
"emoji": "💾",
|
"emoji": "💾",
|
||||||
"previous": "&pAfoMT2ey5mk4X+ABcHQoliXPQaVaeolnTU6ri5P1UI=.sha256"
|
"previous": "&mvGTlWKFR5QM/3nb4fJ2WQq0n/gNKvBmhGDkAvb8ki8=.sha256"
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,17 @@ async function get_names(identities) {
|
|||||||
`, [JSON.stringify(identities)]);
|
`, [JSON.stringify(identities)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function get_most_follows() {
|
||||||
|
return query(`
|
||||||
|
select author, count(*) as count
|
||||||
|
from messages
|
||||||
|
where content ->> 'type' = 'contact' and content ->> 'following' = true
|
||||||
|
group by author
|
||||||
|
order by count desc
|
||||||
|
limit 10;
|
||||||
|
`);
|
||||||
|
}
|
||||||
|
|
||||||
function nice_size(bytes) {
|
function nice_size(bytes) {
|
||||||
let value = bytes;
|
let value = bytes;
|
||||||
let index = 0;
|
let index = 0;
|
||||||
@ -48,12 +59,13 @@ function nice_size(bytes) {
|
|||||||
|
|
||||||
async function main() {
|
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 total = await get_total();
|
||||||
let identities = await ssb.getAllIdentities();
|
let identities = await ssb.getAllIdentities();
|
||||||
let following1 = await ssb.following(identities, 1);
|
let following1 = await ssb.following(identities, 1);
|
||||||
let following2 = await ssb.following(identities, 2);
|
let following2 = await ssb.following(identities, 2);
|
||||||
let biggest = await get_biggest();
|
let biggest = await get_biggest();
|
||||||
let names = await get_names(biggest.map(x => x.author));
|
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]));
|
names = Object.fromEntries(names.map(x => [x.author, x.name]));
|
||||||
for (let item of biggest) {
|
for (let item of biggest) {
|
||||||
item.name = names[item.author];
|
item.name = names[item.author];
|
||||||
@ -63,8 +75,12 @@ async function main() {
|
|||||||
following2[item.author] !== undefined ? 2 :
|
following2[item.author] !== undefined ? 2 :
|
||||||
undefined;
|
undefined;
|
||||||
}
|
}
|
||||||
|
for (let item of most_follows) {
|
||||||
|
item.name = names[item.author];
|
||||||
|
}
|
||||||
let html = `<body style="color: #000; background-color: #ddd">\n
|
let html = `<body style="color: #000; background-color: #ddd">\n
|
||||||
<h1>Top 10 Accounts by Size</h1>
|
<h1>Storage Summary</h1>
|
||||||
|
<h2>Top 10 Accounts by Size</h2>
|
||||||
<ol>`;
|
<ol>`;
|
||||||
for (let item of biggest) {
|
for (let item of biggest) {
|
||||||
html += `<li>
|
html += `<li>
|
||||||
@ -73,6 +89,18 @@ async function main() {
|
|||||||
</li>
|
</li>
|
||||||
\n`;
|
\n`;
|
||||||
}
|
}
|
||||||
|
html += `
|
||||||
|
</ol>
|
||||||
|
<h2>Top 10 Accounts by Follows</h2>
|
||||||
|
<ol>`;
|
||||||
|
for (let item of most_follows) {
|
||||||
|
html += `<li>
|
||||||
|
<span style="color: #888">${item.count}</span>
|
||||||
|
${following2[item.author] ? '✅' : '🚫'}
|
||||||
|
<a target="_top" href="/~core/ssb/#${encodeURI(item.author)}">${item.name ?? item.author}</a>
|
||||||
|
</li>
|
||||||
|
\n`;
|
||||||
|
}
|
||||||
html += `
|
html += `
|
||||||
</ol>
|
</ol>
|
||||||
<p>Total <span style="color: #888">${nice_size(total.size)}</span> in ${total.count} accounts.</p>
|
<p>Total <span style="color: #888">${nice_size(total.size)}</span> in ${total.count} accounts.</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user