Skip to content

Commit 6893d2a

Browse files
authored
Merge pull request #130 from jagerman/cli-react-count
Add room reaction use to CLI room display
2 parents 061e504 + 86c378d commit 6893d2a

File tree

3 files changed

+33
-9
lines changed

3 files changed

+33
-9
lines changed

.drone.jsonnet

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,16 @@ local default_deps = [
2424

2525
local apt_get_quiet = 'apt-get -o=Dpkg::Use-Pty=0 -q';
2626

27-
local setup_commands(deps=default_deps) = [
27+
local auto_distro = '$$(lsb_release -sc)';
28+
29+
local setup_commands(deps=default_deps, distro=auto_distro) = [
2830
'echo "Running on ${DRONE_STAGE_MACHINE}"',
2931
'echo "man-db man-db/auto-update boolean false" | debconf-set-selections',
3032
apt_get_quiet + ' update',
3133
apt_get_quiet + ' install -y eatmydata',
3234
'eatmydata ' + apt_get_quiet + ' install --no-install-recommends -y lsb-release',
3335
'cp contrib/deb.oxen.io.gpg /etc/apt/trusted.gpg.d',
34-
'echo deb http://deb.oxen.io $$(lsb_release -sc) main >/etc/apt/sources.list.d/oxen.list',
36+
'echo deb http://deb.oxen.io ' + distro + ' main >/etc/apt/sources.list.d/oxen.list',
3537
'eatmydata ' + apt_get_quiet + ' update',
3638
'eatmydata ' + apt_get_quiet + ' dist-upgrade -y',
3739
'eatmydata ' + apt_get_quiet + ' install --no-install-recommends -y ' + std.join(' ', deps),
@@ -47,7 +49,8 @@ local debian_pipeline(name,
4749
pytest_opts='',
4850
extra_cmds=[],
4951
services=[],
50-
allow_fail=false) = {
52+
allow_fail=false,
53+
distro=auto_distro) = {
5154
kind: 'pipeline',
5255
type: 'docker',
5356
name: name,
@@ -59,7 +62,7 @@ local debian_pipeline(name,
5962
image: image,
6063
pull: 'always',
6164
[if allow_fail then 'failure']: 'ignore',
62-
commands: setup_commands(deps) + before_pytest + [
65+
commands: setup_commands(deps=deps, distro=distro) + before_pytest + [
6366
'pytest-3 -vv --color=yes ' + pytest_opts,
6467
]
6568
+ extra_cmds,
@@ -73,13 +76,14 @@ local pg_service =
7376
{ name: 'pg', image: 'postgres:bullseye', environment: { POSTGRES_USER: 'ci', POSTGRES_PASSWORD: 'ci' } };
7477
local pg_wait = 'for i in $(seq 0 30); do if pg_isready -d ci -h pg -U ci -t 1; then break; elif [ "$i" = 30 ]; then echo "Timeout waiting for postgresql" >&2; exit 1; fi; sleep 1; done';
7578

76-
local debian_pg_pipeline(name, image, pg_tag='bullseye') = debian_pipeline(
79+
local debian_pg_pipeline(name, image, pg_tag='bullseye', distro=auto_distro) = debian_pipeline(
7780
name,
7881
image,
7982
deps=default_deps + pg_deps,
8083
services=[pg_service],
8184
before_pytest=[pg_wait],
82-
pytest_opts='--pgsql "postgresql://ci:ci@pg/ci"'
85+
pytest_opts='--pgsql "postgresql://ci:ci@pg/ci"',
86+
distro=distro
8387
);
8488

8589
local upgrade_deps = default_deps + ['git', 'curl', 'sqlite3', 'python3-prettytable'];
@@ -133,17 +137,17 @@ local upgrade_test(name, from='v0.1.10', intermediates=[], pg=false, pg_convert=
133137
],
134138
},
135139

136-
debian_pipeline('Debian sid (amd64)', docker_base + 'debian-sid'),
140+
debian_pipeline('Debian sid (amd64)', docker_base + 'debian-sid', distro='sid'),
137141
debian_pipeline('Debian stable (i386)', docker_base + 'debian-stable/i386'),
138142
debian_pipeline('Debian stable (amd64)', docker_base + 'debian-stable'),
139143
debian_pipeline('Ubuntu latest (amd64)', docker_base + 'ubuntu-rolling'),
140144
debian_pipeline('Ubuntu LTS (amd64)', docker_base + 'ubuntu-lts'),
141145

142-
debian_pg_pipeline('PostgreSQL 14/sid', docker_base + 'debian-sid', pg_tag='14-bullseye'),
146+
debian_pg_pipeline('PostgreSQL 14/sid', docker_base + 'debian-sid', pg_tag='14-bullseye', distro='sid'),
143147
debian_pg_pipeline('PostgreSQL 12/focal', docker_base + 'ubuntu-focal', pg_tag='12-bullseye'),
144148

145149
// ARM builds (ARM64 and armhf)
146-
debian_pipeline('Debian sid (ARM64)', docker_base + 'debian-sid', arch='arm64'),
150+
debian_pipeline('Debian sid (ARM64)', docker_base + 'debian-sid', arch='arm64', distro='sid'),
147151
debian_pipeline('Debian stable (armhf)', docker_base + 'debian-stable/arm32v7', arch='arm64'),
148152

149153
// Import tests:

sogs/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ def close_conn():
165165
def print_room(room: Room):
166166
msgs, msgs_size = room.messages_size()
167167
files, files_size = room.attachments_size()
168+
reactions = room.reactions_counts()
169+
r_total = sum(x[1] for x in reactions)
170+
reactions.sort(key=lambda x: x[1], reverse=True)
168171

169172
msgs_size /= 1_000_000
170173
files_size /= 1_000_000
@@ -183,6 +186,7 @@ def print_room(room: Room):
183186
URL: {config.URL_BASE}/{room.token}?public_key={crypto.server_pubkey_hex}
184187
Messages: {msgs} ({msgs_size:.1f} MB)
185188
Attachments: {files} ({files_size:.1f} MB)
189+
Reactions: {r_total}; top 5: {', '.join(f"{r} ({c})" for r, c in reactions[0:5])}
186190
Active users: {active[0]} (1d), {active[1]} (7d), {active[2]} (14d), {active[3]} (30d)
187191
Moderators: {admins} admins ({len(ha)} hidden), {mods} moderators ({len(hm)} hidden)""",
188192
end='',

sogs/model/room.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,22 @@ def attachments_size(self):
10441044
"SELECT COUNT(*), COALESCE(SUM(size), 0) FROM files WHERE room = :r", r=self.id
10451045
).first()[0:2]
10461046

1047+
def reactions_counts(self):
1048+
"""Returns a list of [reaction, count] pairs where count is the aggregate count of that
1049+
reaction use in this room"""
1050+
return [
1051+
(r, c)
1052+
for r, c in query(
1053+
"""
1054+
SELECT reaction, COUNT(*)
1055+
FROM message_reactions JOIN messages ON messages.id = message
1056+
WHERE room = :r
1057+
GROUP BY reaction
1058+
""",
1059+
r=self.id,
1060+
)
1061+
]
1062+
10471063
def get_reactions(
10481064
self,
10491065
message_ids: List[int],

0 commit comments

Comments
 (0)