TLDR- Is there another/better way to purge communities from the database besides doing it one at a time from the webui?
I tried getting a list of communities with curl by adding subscribers_local=0 to the string since that’s how they show up in the DB but it doesn’t seem to be recognized at all, and the request returns all communities that meet the other criteria. That pretty much kills purging via API since I would have to do it one at a time and manually compile the list…Is there a better/faster/less manual way to somehow purge communities based on that criteria besides finding them from the webui and purging them one at a time? This is for hundreds of communities so any level of automation would help.
The only way I can think of is to use the API to get all communities, and then filter out the ones without local subs. So a basic BASH script would be:
#!/bin/bash echo -n '' > /tmp/allcomms.txt page=1 while true do communities=$(curl --request GET --url "https://walledgarden.xyz/api/v3/community/list?type_=All&page=%24%7Bpage%7D&limit=50" --header 'accept: application/json' | jq .communities[]) if [ "${communities}" == "" ] then break fi jq -r '[.community.id, .counts.subscribers_local] | @sh' <<<$communities >> /tmp/allcomms.txt page=$(( page + 1 )) sleep .5 done while read id count do if [ $count -eq 0 ] then echo "$id has no local subs" fi done < /tmp/allcomms.txt
(It’ll take a few minutes to run)
After that, how you purge the communities with those IDs I’m less sure of. My guess would be:
Get a login tokin:
JWT=$(curl --request POST --url https://walledgarden.xyz/api/v3/user/login --header 'accept: application/json' --header 'content-type: application/json' --data '{"username_or_email": "YOUR_USERNAME","password": "YOUR_PASSWORD"}' | jq -r .jwt)
Use Admin/Purge from the API:
curl --request POST --url https://walledgarden.xyz/api/v3/admin/purge/community --header "authorization: Bearer $JWT" --header 'content-type: application/json' --data "{"community_id": ${id}, "reason": "no local subs"}"
As long as purge lets the community be recreated again (which it should do), then that should be okay.
Don’t take my word for any of this for an in-production Lemmy server, though. Test first!
Lemmy has mangled that script a bit.
Where it says ‘%24%7Bpage%7D’, it should a dollar sign, an open curly bracket, the word ‘page’, then a close curly bracket.
It displays a bit better at the source (click the multi-coloured fedi-link thing).
Lemmy has mangled that script a bit.
Lemmy seems to mangle a lot of links that aren’t basic urls. SimpleX chat links break for some reason here too.
Thank you for the suggestions. At this point it seems the best option may be to just shutter this instance and start over with a fresh database instead of dealing with a bunch of nagging problems from previous experiments. I’ve done plenty of testing in production because for most of that time it was only me being affected by the consequences lol.