@@ -35,17 +35,16 @@ def snapshot(service, compose, database):
|
||||
raw = subprocess.check_output(
|
||||
compose + [
|
||||
'exec', '-T', service, 'psql', '-U', 'messenger', '-d', database, '-tAc',
|
||||
"SELECT id::text || '|' || chat_id::text || '|' || text FROM messages "
|
||||
'ORDER BY created_at DESC, id DESC LIMIT 5',
|
||||
"SELECT COALESCE(json_agg(json_build_object("
|
||||
"'id', id::text, 'chat_id', chat_id::text, 'text', text) "
|
||||
"ORDER BY created_at DESC, id DESC), '[]'::json)::text "
|
||||
'FROM (SELECT id, chat_id, text, created_at FROM messages '
|
||||
'ORDER BY created_at DESC, id DESC LIMIT 5) AS sample',
|
||||
],
|
||||
cwd=ROOT,
|
||||
text=True,
|
||||
).strip()
|
||||
sample = []
|
||||
if raw:
|
||||
for line in raw.splitlines():
|
||||
parts = line.split('|', 2)
|
||||
sample.append({'id': parts[0], 'chat_id': parts[1], 'text': parts[2]})
|
||||
sample = json.loads(raw)
|
||||
return {'messages': messages, 'users': users, 'sample': sample}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user