Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Nuke empty communities from db #3401

Closed

Conversation

Matombo
Copy link
Contributor

@Matombo Matombo commented Jun 15, 2018

A script that helps keeping the homeserver clean from empty communities.
Related to issue #3023.

Developer Certificate of Origin
Version 1.1
Signed-off-by: Werner Sembach <werner.sembach at fau.de>

@matrixbot
Copy link
Member

Can one of the admins verify this patch?

1 similar comment
@matrixbot
Copy link
Member

Can one of the admins verify this patch?

quit()

with db:
cur.execute('SELECT group_id FROM groups;')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can extend this query to the following to not need the check in the for loop:

SELECT g.group_id FROM groups g
    WHERE (SELECT count(*) from group_users u WHERE g.group_id = u.group_id) = 0

@Matombo
Copy link
Contributor Author

Matombo commented Jun 16, 2018

Thanks for pointing this out.
I incorporated the change.

@ArchangeGabriel
Copy link
Contributor

Does it works when using PostgreSQL through UNIX socket? I believe not, because you are forcing the use of too many parameters for this case.

@Matombo
Copy link
Contributor Author

Matombo commented Jun 27, 2018

I don't have much PostgreSQL knowledge.
Can you plese point me out on which parameters of those 4 are necessary and which are optional?

@ArchangeGabriel
Copy link
Contributor

AFAIK only dbname is required, because you can use peer authentication when using UNIX Socket, so that no username, password or host is required.

@Matombo Matombo force-pushed the nuke_empty_communities_from_db branch from c56c5a4 to b3de5ed Compare June 27, 2018 17:31
@@ -1,33 +1,49 @@
#!/usr/bin/env python2

from sys import argv
from getopt import getopt
import sqlite3
import psycopg2

if len(argv) < 3 or (argv[1] != "sqlite" and argv[1] != "postgresql") or (argv[1] == "postgresql" and len(argv) < 6):
Copy link
Contributor

@ArchangeGabriel ArchangeGabriel Jun 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the 6 at the end of this line still makes options mandatory in practice.

@Matombo
Copy link
Contributor Author

Matombo commented Jun 27, 2018

Woops forget that line
Corrected
Thanks

@Matombo
Copy link
Contributor Author

Matombo commented Aug 6, 2018

What exactly is the Synapse Sytest?
Do i have to do anything for it to finish?

@codecov-io
Copy link

codecov-io commented Feb 20, 2019

Codecov Report

❗ No coverage uploaded for pull request base (develop@23ea572). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff             @@
##             develop    #3401   +/-   ##
==========================================
  Coverage           ?   75.16%           
==========================================
  Files              ?      340           
  Lines              ?    34811           
  Branches           ?     5701           
==========================================
  Hits               ?    26166           
  Misses             ?     7033           
  Partials           ?     1612

@Matombo
Copy link
Contributor Author

Matombo commented Feb 20, 2019

should i move this script to contrib folder?

@dragetd
Copy link

dragetd commented Feb 22, 2019

Wouldn't it be a lot better if we stick to prepared states instead of executing MySQL Strings?

@aaronraimist
Copy link
Contributor

There is an API to delete groups now so this script probably isn't needed anymore https://github.com/matrix-org/synapse/blob/master/docs/admin_api/delete_group.md

@Matombo
Copy link
Contributor Author

Matombo commented Dec 2, 2019

The api only deletes single groups by id. This script scans the database for empty groups and deletes them.

This script still serves an unique function but needs to be updated to use the new api.

@Matombo
Copy link
Contributor Author

Matombo commented Dec 2, 2019

Thinking about the new api this would actually limit the script funtionality.

The api uses a http interface, so it can only be used while the server is running. This script can be directly executed on the database of an online or offline instance.

Also, the api currently only supports deleting groups, not to search all groups and select them according to members count. The script still needs to issue sql statements even when using the api.

@Matombo
Copy link
Contributor Author

Matombo commented Dec 16, 2019

Made obsolete by: #6453

@Matombo Matombo closed this Dec 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants