#!/usr/bin/env python3 """Make docmost the BIG database of the chaos hour, through its own API with ONE login (its login is rate-limited: 290 of 300 per-call logins answered 401 in setup). Spaces with a 4 KB description each, then the database size asked of PostgreSQL itself.""" import json, os, sys, time sys.path.insert(0, ".") import walk as w from chaos import load, save, sub_of s = load(); A = s["apps"]["docmost"]["A"]; sub = sub_of("docmost") w.login() jar = f"{w.SC}/big.jar" rc, code, out = w.app_curl(sub, "/api/auth/login", "-c", jar, "-H", "Content-Type: application/json", data=json.dumps({"email": A["email"], "password": A["pw"]}), method="POST") w.say(f"login http={code}") ok = 0 desc = ("chaos-hour big database filler " * 140)[:4000] for i in range(400): name = f"big{i:03d}{os.urandom(2).hex()}" rc, code, out = w.app_curl(sub, "/api/spaces/create", "-b", jar, "-H", "Content-Type: application/json", data=json.dumps({"name": name, "slug": name, "description": desc}), method="POST") if code in ("200", "201"): ok += 1 elif i < 5 or i % 50 == 0: w.say(f" {i}: http={code} {out[:120]}") w.say(f"created {ok} spaces with one login") size = w.guest("docker exec docmost-postgres psql -U docmost -d docmost -Atc \"select pg_size_pretty(pg_database_size('docmost')), (select count(*) from spaces)\"") w.say(f"docmost database: {size.strip()}") s["apps"]["docmost"]["big_extra_spaces"] = s["apps"]["docmost"].get("big_extra_spaces", 0) + ok s["apps"]["docmost"]["db_size"] = size.strip() save(s) open("chaos/00-bigdb.log", "w").write("\n".join(w.LOG) + "\n")