diff --git a/MR_DESCRIPTION.md b/MR_DESCRIPTION.md index 1f5095f5..6266fc4d 100644 --- a/MR_DESCRIPTION.md +++ b/MR_DESCRIPTION.md @@ -2,12 +2,16 @@ Автор: Майорова Софья, БВТ2301. Целевая оценка 5, трек 2 — план запроса и восстановление. +ЛР 1 отправлена: https://gitflic.ru/project/vmd/mtusi2026lab1/merge-request/140 + Собственная реализация lab1 перенесена на PostgreSQL. Добавлены версионируемая миграция, PK/FK/UNIQUE, атомарное создание чата, ограниченный connection pool и таймауты. Регистрация использует scrypt, Basic выдаёт opaque Bearer-сессию; сессии с expiry и logout хранятся в PostgreSQL. Redis реально кэширует публичные профили с TTL; отказ кэша не отменяет проверку сессии в БД и не мешает работе. -Проверки: `make check validate`, `make test`, восемь собственных тестов, сохранность данных и прежнего токена после рестарта API/PostgreSQL/Redis, expiry=2 с, logout, неправильный пароль, гонка username, rollback, отказы Redis/PostgreSQL и восстановление. Найденный собственными тестами OOM при параллельном scrypt исправлен ограничением KDF, повторный тест проходит при прежнем лимите 256 MiB. +Проверки: `make check validate`, `make test`, девять собственных тестов, сохранность данных и прежнего токена после рестарта API/PostgreSQL/Redis, expiry=2 с, logout, неправильный пароль, гонка username, rollback, отказы Redis/PostgreSQL и восстановление. Найденный собственными тестами OOM при параллельном scrypt исправлен ограничением KDF, повторный тест проходит при прежнем лимите 256 MiB. Исследование на 100000 сообщений в десяти чатах разного размера: два индекса, EXPLAIN ANALYZE BUFFERS, пять повторов чтения, три измерения записи с COMMIT и WAL. Backup восстановлен в другой PostgreSQL-контейнер на новом volume; количества, пять выбранных сообщений и SHA-256 всей истории совпали. Полные планы, результаты и ограничения — в `evidence/index-study.json` и `REPORT.md`. +Исправлены замечания ревью: U+0000 сохраняется без потерь в display_name/title/text через UTF-8 BYTEA и миграцию 002; девятый тест проверяет полный round trip, кэш и границы длины. Проверен полный restart с NUL-содержащими строками. Restore ожидает TCP-готовность финального PostgreSQL; три новых независимых volume восстановлены с полной сверкой 100000 сообщений и контрольной строкой с U+0000. Вывод в evidence/review-*. + Запуск из чистого clone: `python3 scripts/bootstrap.py`, `docker compose up -d --build --wait`, `make check test test-student`, `make test-persistence ACTION_SCRIPT=scripts/restart.sh`, `make test-dependencies`, `make research`. - [x] Минимум предыдущей работы сохранён с переходом на сессии. diff --git a/REPORT.md b/REPORT.md index f9b8f893..34f040ff 100644 --- a/REPORT.md +++ b/REPORT.md @@ -37,7 +37,7 @@ make validate PYTHON=.venv/bin/python `Клиент → API → PostgreSQL`; Redis кэширует неизменяемые публичные профили `User`. PostgreSQL — источник истины для пользователей, чатов, участников, сообщений и сессий. История сообщений никогда не берётся из Redis: успешный COMMIT виден следующему чтению. Удаления/редактирования профилей в контракте нет, поэтому cache-aside профиля не нарушает read-after-write истории. -Схема в `migrations/001_initial.sql`: +Схема в `migrations/001_initial.sql`; миграция `002_unicode_nul.sql` сохраняет существующие строки и переводит display_name/title/text в UTF-8 BYTEA: - `users`: UUID PK, UNIQUE username, display_name, scrypt hash, server timestamp. - `chats`: UUID PK, title, created_at, last_message_at. @@ -46,6 +46,8 @@ make validate PYTHON=.venv/bin/python - `sessions`: PK SHA-256 случайного токена, FK user_id, expiry и индекс expiry. SHA-256 здесь индексирует высокоэнтропийный токен, **не пароль**. - `schema_migrations`: применённые имена версий. Advisory transaction lock исключает одновременное применение миграции несколькими API. +PostgreSQL TEXT не поддерживает U+0000, хотя контракт допускает его в Unicode-строке. Три пользовательских поля хранятся как UTF-8 bytes в BYTEA, на границе API кодируются/декодируются без потерь. Python проверяет длину в code points (100/100/4000); ограничения БД дополнительно ограничивают UTF-8 размер 400/400/16000 байт. Username, password_hash и данные сессий остаются TEXT. Миграция конвертирует прежние строки через convert_to. [TEXT](https://www.postgresql.org/docs/17/datatype-character.html), [BYTEA](https://www.postgresql.org/docs/17/datatype-binary.html). + Создание чата, проверка всех участников и вставка членства — одна транзакция. Ошибка неизвестного участника после INSERT чата откатывает весь составной объект; собственный тест проверяет отсутствие даже невидимого orphan через SQL COUNT. Запись сообщения и увеличение `last_message_at` — одна транзакция. UPDATE строки чата сериализует timestamp внутри чата; сервер выбирает max(часы, предыдущий timestamp + 1 мкс). Это сохраняет порядок keyset при конкурентных отправках и переводе часов назад. Уровень изоляции — PostgreSQL READ COMMITTED; snapshot между HTTP-страницами не обещается. @@ -77,16 +79,16 @@ API ограничен 1 CPU / 256 MiB; PostgreSQL — 1 CPU / 512 MiB; Redis ## Доказательства критериев -Дополнительно выполнен чистый локальный `git clone` сдаваемого решения: сборка из клона и все применимые smoke/собственные тесты прошли. Для lab2 стенд создан на новом пустом volume, миграция применена один раз и persistence-сценарий пройден с прежним токеном. Вывод: `evidence/clean-clone.txt`. +После исправлений выполнен новый чистый локальный git clone, сборка и запуск на новом пустом volume. Применены обе миграции 001/002; публичный smoke и все девять собственных тестов проходят: `evidence/review-clean-clone.txt`. Первичный прогон до ревью сохранён в `evidence/clean-clone.txt`. Сохранность и отказы текущей версии дополнительно проверены: `evidence/review-persistence.txt`, `evidence/review-dependencies.txt`. | Критерий | Команда / сценарий | Реальный результат | Файл | | --- | --- | --- | --- | | Offline / OpenAPI | `make check`, `make validate` | PASS | `evidence/check.txt`, `evidence/validation.txt` | | Обязательный API | `make test` | PASS lab2 | `evidence/smoke.txt` | -| Негативные сценарии и Unicode | `make test-student` | 8 тестов, все PASS | `evidence/student-tests.txt` | +| Негативные сценарии и Unicode | `make test-student` | 9 тестов, все PASS, включая U+0000 | `evidence/review-tests.txt` | | Конкурентные сообщения / cursor | тот же набор, 100 POST / 10 клиентов | 100 уникальных ID, без потерь | тот же файл | | Гонка username | тот же набор | ровно один 201, девять 409 | тот же файл | -| FK/UNIQUE/миграции с нуля | первый `compose up`, повторные старты | таблицы созданы; версия 001 применена один раз | `migrations/001_initial.sql`, `evidence/runtime.json` | +| FK/UNIQUE/миграции с нуля | первый `compose up`, повторные старты | версии 001/002 применены; исследование создаёт схему с нуля | `migrations/`, `evidence/review-restore-runs.json` | | Атомарность составного чата | `make test-dependencies`, SQL COUNT до/после | rollback, количество chats не изменилось | `evidence/dependencies.json` | | Сохранность данных и прежнего токена | `make test-persistence ACTION_SCRIPT=scripts/restart.sh` | PASS после рестарта API + PostgreSQL + Redis | `evidence/persistence.txt` | | Реальность restart hook | сравнение StartedAt и volumes всех трёх services | процессы новые по времени старта, том PostgreSQL тот же | `evidence/restart-before.json`, `evidence/restart-after.json` | @@ -103,18 +105,18 @@ API ограничен 1 CPU / 256 MiB; PostgreSQL — 1 CPU / 512 MiB; Redis Гипотеза: индекс только по chat_id заставляет отфильтровывать/сортировать значительную часть большого чата при глубоком cursor. B-tree `(chat_id, created_at, id)` позволит читать limit+1 сразу из нужного диапазона; за это придётся платить размером индекса и записью WAL. -`student-tests/index_study.py` создаёт **отдельную синтетическую БД**, не заполняет рабочие чаты тестового API. Размеры десяти чатов: **70000, 20000, 5000, 2000, 1000, 800, 500, 300, 200, 200** — суммарно 100000. Текст — 64 символа, UUID случайные, timestamp с шагом 1 мкс. Сравниваются `messages_history(chat_id)` и `messages_history(chat_id, created_at, id)`; PK(id) и прочие ограничения одинаковы. +`student-tests/index_study.py` создаёт **отдельную синтетическую БД**, не заполняет рабочие чаты тестового API. Размеры десяти чатов: **70000, 20000, 5000, 2000, 1000, 800, 500, 300, 200, 200** — суммарно 100000. Текст — 64 байта UTF-8. Одна контрольная строка содержит U+0000 и имеет UUID=0, чтобы обязательно попасть в образцы backup/restore; остальные UUID случайные. Timestamp с шагом 1 мкс. Сравниваются `messages_history(chat_id)` и `messages_history(chat_id, created_at, id)`; PK(id) и прочие ограничения одинаковы. Запрос совпадает с API keyset: фильтр chat_id и `(created_at,id)>cursor`, ORDER BY created_at,id, LIMIT 51. Для чатов 70000, 20000 и 200 cursor ставится на 80% истории. Перед замером — ANALYZE и один прогрев; затем пять `EXPLAIN (ANALYZE, BUFFERS, FORMAT JSON)`, без отключения seqscan и других подсказок планировщику. Сохранены все планы, включая buffers. Поочерёдно меняется один индекс. | Индекс | Сообщений в чате | Медиана Execution Time, мс | | --- | --- | --- | -| chat_only | 70000 | 26.665 | -| chat_only | 20000 | 7.168 | -| chat_only | 200 | 0.073 | -| composite | 70000 | 0.057 | -| composite | 20000 | 0.072 | -| composite | 200 | 0.065 | +| chat_only | 70000 | 4.463 | +| chat_only | 20000 | 1.273 | +| chat_only | 200 | 0.020 | +| composite | 70000 | 0.011 | +| composite | 20000 | 0.011 | +| composite | 200 | 0.008 | Для большого чата простой индекс приводит к полному/широкому проходу и сортировке, составной — к ограниченному индексному диапазону. Для маленького чата разница близка к шуму. Сам API использует составной индекс из миграции. @@ -122,8 +124,8 @@ API ограничен 1 CPU / 256 MiB; PostgreSQL — 1 CPU / 512 MiB; Redis | Индекс | Размер индекса, байт | Медиана COPY+COMMIT 1000 строк, мс | Медиана WAL, байт | | --- | --- | --- | --- | -| chat_only | 753664 | 88.455 | 245480 | -| composite | 6127616 | 329.823 | 322672 | +| chat_only | 753664 | 9.849 | 241648 | +| composite | 6127616 | 9.935 | 311584 | Большой индекс ускоряет чтение, но увеличивает занимаемое место и WAL. Время записи в этих коротких последовательных прогонах заметно колеблется, на него влияют checkpoint, кэш, COPY, CPU quota и фоновые процессы; три повтора не дают универсального коэффициента замедления. Порядок вариантов фиксирован, cold-cache I/O не исследовался. Это анализ query plan и компромисса индекса, не измерение HTTP RPS всего приложения. @@ -133,23 +135,29 @@ API ограничен 1 CPU / 256 MiB; PostgreSQL — 1 CPU / 512 MiB; Redis 1. Запускает исследование в отдельной БД; делает `pg_dump -Fc` согласованного снимка. 2. Создаёт **другой PostgreSQL-контейнер с новым именованным volume**, тем же закреплённым образом и собственным каталогом данных; порты хоста не публикуются. -3. Выполняет `pg_restore --exit-on-error` в новую пустую БД. +3. Ожидает TCP-готовность на 127.0.0.1, затем выполняет `pg_restore -h 127.0.0.1 --exit-on-error` в новую пустую БД. Временный Unix-socket сервер инициализации не проходит эту проверку. 4. Сравнивает количества users/chats/chat_members/messages/sessions, пять выбранных сообщений и SHA-256 **всех 100000 сообщений** в порядке UUID, включая поля сообщений. В research fixture sessions=0; сохранность действующей сессии отдельно доказана persistence-тестом. 5. Сохраняет JSON-сводку, останавливает restore-контейнер; backup и новый volume оставляет для проверки. -Размер dump: 2655979 байт. Dump: 1.102 с; bootstrap нового PostgreSQL: 2.588 с; собственно pg_restore: 1.742 с. Bootstrap + восстановление: 4.330 с, **без времени последующей проверки checksum**. Это время локального учебного набора, не RTO большого сервиса. +Размер dump: 2655198 байт. Dump: 0.280 с; bootstrap нового PostgreSQL: 0.820 с; pg_restore: 0.267 с. Bootstrap + восстановление: 1.087 с, без последующей проверки checksum. Это локальный учебный набор, не RTO большого сервиса. -Исходный volume: `mtusi-lab2_postgres_data`; новый: `mtusi-lab2-restore_70a1c2c75a5c-data`. Различные ID процессов/контейнеров и обе сверки приведены в JSON. Бэкап не коммитится. -Восстановленный SHA-256 истории: `0f90589eece3910789d2eae40d5685c80cdf9f93e414aca19893851e85ffb071`. +Исходный volume: `mtusi-lab2_postgres_data`; новый: `mtusi-lab2-restore_4bc6680354a1-data`. Разные ID контейнеров и полный результат сверки — в JSON. Backup не коммитится. +Восстановленный SHA-256 истории: `8c3e317ab75daa8a5e97641eac51e3a349cffe2293bb83bc2ba22ce602cbf112`. ### Отказы и ограничения durability -При потере Redis обязательных данных не теряется, кэш восстановим. В тесте чтение/запись/проверки при выключенном Redis заняли 0.297 с суммарно. При выключенном PostgreSQL первый защищённый запрос вернул 503 за 0.007 с; анонимный доступ не разрешался. После возврата зависимостей исходная сессия работала. +При потере Redis обязательных данных не теряется, кэш восстановим. В тесте чтение/запись/проверки при выключенном Redis заняли 0.050 с суммарно. При выключенном PostgreSQL первый защищённый запрос вернул 503 за 0.004 с; анонимный доступ не разрешался. После возврата зависимостей исходная сессия работала. Рестарт контейнера с сохранённым volume не теряет подтверждённые данные при обычных настройках PostgreSQL fsync/synchronous_commit. Он не доказывает устойчивость к поломке диска/host или потере volume. Резервная копия даёт состояние на момент snapshot pg_dump: сообщения после этого снимка будут потеряны при восстановлении только из данного backup. PITR/WAL archiving, репликация PostgreSQL и HA не реализованы. Readiness честно становится 503 без БД. Учебные ограничения: один PostgreSQL и один API; DB-role bootstrap владеет учебной БД, ограничение его production-прав не сделано. Накопленные истёкшие сессии не обслуживаются, но фоновый cleanup таблицы пока не добавлен. Redis не кэширует историю и не сокращает обязательную проверку сессии в БД. Общий HTTP-слой не предназначен для публичного Internet-deployment без TLS/reverse proxy. +## Исправления по замечаниям преподавателя + +- U+0000: миграция 002 и lossless UTF-8 BYTEA для трёх строковых полей. Новый black-box тест проверяет NUL, буквальную последовательность backslash-u0000, emoji, границу 4000 code points, профиль из login/БД/Redis, title и чтение истории. Девять собственных тестов и публичный smoke проходят: `evidence/review-tests.txt`. +- Сохранность: профиль, чат и сообщение с U+0000 без изменений прочитаны после рестарта API/PostgreSQL/Redis, прежний Bearer действителен: `evidence/review-unicode-persistence.txt`. +- Гонка init-сервера: readiness и restore используют TCP. Три последовательных полных исследования с новыми контейнерами и томами прошли; каждый раз совпали counts, выбранные строки (включая NUL) и SHA-256 всей истории: `evidence/review-research.txt`, `evidence/review-restore-runs.json`. Метрики выше обновлены по последнему прогону текущей схемы. + ## Коротко для защиты COMMIT подтверждает транзакцию; устойчивость зависит от WAL, fsync, synchronous_commit и сохранности носителя. Аутентификация определяет пользователя по Bearer, членство отдельно определяет доступ к чату. Flush/restart Redis затрагивает только кэш профилей; сессии остаются в PostgreSQL. Password KDF намеренно затратен и использует соль, быстрый checksum для паролей не подходит. diff --git a/compose.yaml b/compose.yaml index 947c8bf5..b55469dd 100644 --- a/compose.yaml +++ b/compose.yaml @@ -30,7 +30,7 @@ services: volumes: - postgres_data:/var/lib/postgresql/data healthcheck: - test: ["CMD-SHELL", "pg_isready -U messenger -d messenger"] + test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -U messenger -d messenger"] interval: 3s timeout: 2s retries: 20 diff --git a/evidence/dependencies.json b/evidence/dependencies.json index 3a9ac2aa..b5f3096d 100644 --- a/evidence/dependencies.json +++ b/evidence/dependencies.json @@ -1,9 +1,9 @@ { "composite_operation_rollback": true, "redis_user_cache_ttl_seconds": 60, - "redis_outage_seconds": 0.2969403329999998, + "redis_outage_seconds": 0.05048745900000007, "redis_recovered_without_relogin": true, - "postgres_outage_response_seconds": 0.006768832999999752, + "postgres_outage_response_seconds": 0.004356375000000412, "postgres_recovered_without_relogin": true, "short_ttl_expired": true } \ No newline at end of file diff --git a/evidence/index-study.json b/evidence/index-study.json index 979d39cb..06fd053f 100644 --- a/evidence/index-study.json +++ b/evidence/index-study.json @@ -1,5 +1,5 @@ { - "database": "research_e3a4181a6e18", + "database": "research_09efbd8b091e", "postgresql": "PostgreSQL 17.2 (Debian 17.2-1.pgdg120+1) on aarch64-unknown-linux-gnu, compiled by gcc (Debian 12.2.0-14) 12.2.0, 64-bit", "sizes": [ 70000, @@ -22,22 +22,22 @@ "reads": [ { "chat_messages": 70000, - "median_execution_ms": 26.665, + "median_execution_ms": 4.463, "plans": [ { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4041.77, + "Startup Cost": 3652.04, + "Total Cost": 3652.17, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 30.76, - "Actual Total Time": 30.778, + "Actual Startup Time": 4.573, + "Actual Total Time": 4.576, "Actual Rows": 51, "Actual Loops": 1, - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -53,12 +53,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4065.9, - "Plan Rows": 9701, + "Startup Cost": 3652.04, + "Total Cost": 3676.02, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 30.757, - "Actual Total Time": 30.766, + "Actual Startup Time": 4.572, + "Actual Total Time": 4.574, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -68,7 +68,7 @@ "Sort Method": "top-N heapsort", "Sort Space Used": 38, "Sort Space Type": "Memory", - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -80,23 +80,27 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Seq Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 0.0, - "Total Cost": 3718.0, - "Plan Rows": 9701, + "Startup Cost": 0.29, + "Total Cost": 3332.03, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 13.769, - "Actual Total Time": 27.723, + "Actual Startup Time": 2.901, + "Actual Total Time": 3.89, "Actual Rows": 14000, "Actual Loops": 1, - "Filter": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", - "Rows Removed by Filter": 86000, - "Shared Hit Blocks": 1968, + "Index Cond": "(chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", + "Rows Removed by Filter": 56000, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -123,24 +127,24 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.36, + "Planning Time": 0.023, "Triggers": [], - "Execution Time": 30.825 + "Execution Time": 4.581 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4041.77, + "Startup Cost": 3652.04, + "Total Cost": 3652.17, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 31.086, - "Actual Total Time": 31.104, + "Actual Startup Time": 4.456, + "Actual Total Time": 4.459, "Actual Rows": 51, "Actual Loops": 1, - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -156,12 +160,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4065.9, - "Plan Rows": 9701, + "Startup Cost": 3652.04, + "Total Cost": 3676.02, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 31.083, - "Actual Total Time": 31.093, + "Actual Startup Time": 4.455, + "Actual Total Time": 4.457, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -171,7 +175,7 @@ "Sort Method": "top-N heapsort", "Sort Space Used": 38, "Sort Space Type": "Memory", - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -183,23 +187,27 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Seq Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 0.0, - "Total Cost": 3718.0, - "Plan Rows": 9701, + "Startup Cost": 0.29, + "Total Cost": 3332.03, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 15.316, - "Actual Total Time": 27.916, + "Actual Startup Time": 2.801, + "Actual Total Time": 3.779, "Actual Rows": 14000, "Actual Loops": 1, - "Filter": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", - "Rows Removed by Filter": 86000, - "Shared Hit Blocks": 1968, + "Index Cond": "(chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", + "Rows Removed by Filter": 56000, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -226,24 +234,24 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.179, + "Planning Time": 0.022, "Triggers": [], - "Execution Time": 31.149 + "Execution Time": 4.463 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4041.77, + "Startup Cost": 3652.04, + "Total Cost": 3652.17, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 26.299, - "Actual Total Time": 26.316, + "Actual Startup Time": 4.463, + "Actual Total Time": 4.466, "Actual Rows": 51, "Actual Loops": 1, - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -259,12 +267,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4065.9, - "Plan Rows": 9701, + "Startup Cost": 3652.04, + "Total Cost": 3676.02, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 26.296, - "Actual Total Time": 26.304, + "Actual Startup Time": 4.462, + "Actual Total Time": 4.464, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -274,7 +282,7 @@ "Sort Method": "top-N heapsort", "Sort Space Used": 38, "Sort Space Type": "Memory", - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -286,23 +294,27 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Seq Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 0.0, - "Total Cost": 3718.0, - "Plan Rows": 9701, + "Startup Cost": 0.29, + "Total Cost": 3332.03, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 12.752, - "Actual Total Time": 23.574, + "Actual Startup Time": 2.802, + "Actual Total Time": 3.776, "Actual Rows": 14000, "Actual Loops": 1, - "Filter": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", - "Rows Removed by Filter": 86000, - "Shared Hit Blocks": 1968, + "Index Cond": "(chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", + "Rows Removed by Filter": 56000, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -329,24 +341,24 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.164, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 26.394 + "Execution Time": 4.47 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4041.77, + "Startup Cost": 3652.04, + "Total Cost": 3652.17, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 21.487, - "Actual Total Time": 21.501, + "Actual Startup Time": 4.413, + "Actual Total Time": 4.417, "Actual Rows": 51, "Actual Loops": 1, - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -362,12 +374,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4065.9, - "Plan Rows": 9701, + "Startup Cost": 3652.04, + "Total Cost": 3676.02, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 21.484, - "Actual Total Time": 21.492, + "Actual Startup Time": 4.413, + "Actual Total Time": 4.415, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -377,7 +389,7 @@ "Sort Method": "top-N heapsort", "Sort Space Used": 38, "Sort Space Type": "Memory", - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -389,23 +401,27 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Seq Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 0.0, - "Total Cost": 3718.0, - "Plan Rows": 9701, + "Startup Cost": 0.29, + "Total Cost": 3332.03, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 11.832, - "Actual Total Time": 19.56, + "Actual Startup Time": 2.758, + "Actual Total Time": 3.727, "Actual Rows": 14000, "Actual Loops": 1, - "Filter": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", - "Rows Removed by Filter": 86000, - "Shared Hit Blocks": 1968, + "Index Cond": "(chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", + "Rows Removed by Filter": 56000, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -432,24 +448,24 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.175, + "Planning Time": 0.012, "Triggers": [], - "Execution Time": 21.542 + "Execution Time": 4.42 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4041.77, + "Startup Cost": 3652.04, + "Total Cost": 3652.17, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 26.592, - "Actual Total Time": 26.628, + "Actual Startup Time": 4.346, + "Actual Total Time": 4.35, "Actual Rows": 51, "Actual Loops": 1, - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -465,12 +481,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 4041.65, - "Total Cost": 4065.9, - "Plan Rows": 9701, + "Startup Cost": 3652.04, + "Total Cost": 3676.02, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 26.589, - "Actual Total Time": 26.597, + "Actual Startup Time": 4.346, + "Actual Total Time": 4.347, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -480,7 +496,7 @@ "Sort Method": "top-N heapsort", "Sort Space Used": 38, "Sort Space Type": "Memory", - "Shared Hit Blocks": 1968, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -492,23 +508,27 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Seq Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 0.0, - "Total Cost": 3718.0, - "Plan Rows": 9701, + "Startup Cost": 0.29, + "Total Cost": 3332.03, + "Plan Rows": 9592, "Plan Width": 121, - "Actual Startup Time": 12.442, - "Actual Total Time": 23.672, + "Actual Startup Time": 2.7, + "Actual Total Time": 3.669, "Actual Rows": 14000, "Actual Loops": 1, - "Filter": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", - "Rows Removed by Filter": 86000, - "Shared Hit Blocks": 1968, + "Index Cond": "(chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid)", + "Rows Removed by Index Recheck": 0, + "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", + "Rows Removed by Filter": 56000, + "Shared Hit Blocks": 1408, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -535,27 +555,27 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.163, + "Planning Time": 0.011, "Triggers": [], - "Execution Time": 26.665 + "Execution Time": 4.353 } ] }, { "chat_messages": 20000, - "median_execution_ms": 7.168, + "median_execution_ms": 1.273, "plans": [ { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2930.04, + "Startup Cost": 1487.53, + "Total Cost": 1487.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 9.52, - "Actual Total Time": 9.544, + "Actual Startup Time": 1.251, + "Actual Total Time": 1.254, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 404, @@ -574,12 +594,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2958.91, - "Plan Rows": 11599, + "Startup Cost": 1487.53, + "Total Cost": 1516.61, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 9.517, - "Actual Total Time": 9.524, + "Actual Startup Time": 1.251, + "Actual Total Time": 1.252, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -601,26 +621,26 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Bitmap Heap Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 225.12, - "Total Cost": 2542.94, - "Plan Rows": 11599, + "Startup Cost": 0.29, + "Total Cost": 1099.46, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 7.18, - "Actual Total Time": 8.888, + "Actual Startup Time": 0.765, + "Actual Total Time": 1.042, "Actual Rows": 4000, "Actual Loops": 1, - "Recheck Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", + "Index Cond": "(chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 16000, - "Exact Heap Blocks": 385, - "Lossy Heap Blocks": 0, "Shared Hit Blocks": 404, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, @@ -630,35 +650,7 @@ "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, - "Temp Written Blocks": 0, - "Plans": [ - { - "Node Type": "Bitmap Index Scan", - "Parent Relationship": "Outer", - "Parallel Aware": false, - "Async Capable": false, - "Index Name": "messages_history", - "Startup Cost": 0.0, - "Total Cost": 222.22, - "Plan Rows": 19990, - "Plan Width": 0, - "Actual Startup Time": 1.674, - "Actual Total Time": 1.674, - "Actual Rows": 20000, - "Actual Loops": 1, - "Index Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", - "Shared Hit Blocks": 19, - "Shared Read Blocks": 0, - "Shared Dirtied Blocks": 0, - "Shared Written Blocks": 0, - "Local Hit Blocks": 0, - "Local Read Blocks": 0, - "Local Dirtied Blocks": 0, - "Local Written Blocks": 0, - "Temp Read Blocks": 0, - "Temp Written Blocks": 0 - } - ] + "Temp Written Blocks": 0 } ] } @@ -676,21 +668,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.224, + "Planning Time": 0.016, "Triggers": [], - "Execution Time": 9.591 + "Execution Time": 1.259 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2930.04, + "Startup Cost": 1487.53, + "Total Cost": 1487.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 5.88, - "Actual Total Time": 5.892, + "Actual Startup Time": 1.266, + "Actual Total Time": 1.269, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 404, @@ -709,12 +701,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2958.91, - "Plan Rows": 11599, + "Startup Cost": 1487.53, + "Total Cost": 1516.61, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 5.877, - "Actual Total Time": 5.883, + "Actual Startup Time": 1.265, + "Actual Total Time": 1.267, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -736,26 +728,26 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Bitmap Heap Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 225.12, - "Total Cost": 2542.94, - "Plan Rows": 11599, + "Startup Cost": 0.29, + "Total Cost": 1099.46, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 4.382, - "Actual Total Time": 5.336, + "Actual Startup Time": 0.791, + "Actual Total Time": 1.061, "Actual Rows": 4000, "Actual Loops": 1, - "Recheck Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", + "Index Cond": "(chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 16000, - "Exact Heap Blocks": 385, - "Lossy Heap Blocks": 0, "Shared Hit Blocks": 404, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, @@ -765,35 +757,7 @@ "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, - "Temp Written Blocks": 0, - "Plans": [ - { - "Node Type": "Bitmap Index Scan", - "Parent Relationship": "Outer", - "Parallel Aware": false, - "Async Capable": false, - "Index Name": "messages_history", - "Startup Cost": 0.0, - "Total Cost": 222.22, - "Plan Rows": 19990, - "Plan Width": 0, - "Actual Startup Time": 0.669, - "Actual Total Time": 0.67, - "Actual Rows": 20000, - "Actual Loops": 1, - "Index Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", - "Shared Hit Blocks": 19, - "Shared Read Blocks": 0, - "Shared Dirtied Blocks": 0, - "Shared Written Blocks": 0, - "Local Hit Blocks": 0, - "Local Read Blocks": 0, - "Local Dirtied Blocks": 0, - "Local Written Blocks": 0, - "Temp Read Blocks": 0, - "Temp Written Blocks": 0 - } - ] + "Temp Written Blocks": 0 } ] } @@ -811,21 +775,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.246, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 6.031 + "Execution Time": 1.273 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2930.04, + "Startup Cost": 1487.53, + "Total Cost": 1487.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 7.114, - "Actual Total Time": 7.129, + "Actual Startup Time": 1.304, + "Actual Total Time": 1.308, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 404, @@ -844,12 +808,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2958.91, - "Plan Rows": 11599, + "Startup Cost": 1487.53, + "Total Cost": 1516.61, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 7.112, - "Actual Total Time": 7.119, + "Actual Startup Time": 1.304, + "Actual Total Time": 1.306, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -871,26 +835,26 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Bitmap Heap Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 225.12, - "Total Cost": 2542.94, - "Plan Rows": 11599, + "Startup Cost": 0.29, + "Total Cost": 1099.46, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 4.52, - "Actual Total Time": 6.217, + "Actual Startup Time": 0.792, + "Actual Total Time": 1.09, "Actual Rows": 4000, "Actual Loops": 1, - "Recheck Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", + "Index Cond": "(chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 16000, - "Exact Heap Blocks": 385, - "Lossy Heap Blocks": 0, "Shared Hit Blocks": 404, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, @@ -900,35 +864,7 @@ "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, - "Temp Written Blocks": 0, - "Plans": [ - { - "Node Type": "Bitmap Index Scan", - "Parent Relationship": "Outer", - "Parallel Aware": false, - "Async Capable": false, - "Index Name": "messages_history", - "Startup Cost": 0.0, - "Total Cost": 222.22, - "Plan Rows": 19990, - "Plan Width": 0, - "Actual Startup Time": 0.735, - "Actual Total Time": 0.736, - "Actual Rows": 20000, - "Actual Loops": 1, - "Index Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", - "Shared Hit Blocks": 19, - "Shared Read Blocks": 0, - "Shared Dirtied Blocks": 0, - "Shared Written Blocks": 0, - "Local Hit Blocks": 0, - "Local Read Blocks": 0, - "Local Dirtied Blocks": 0, - "Local Written Blocks": 0, - "Temp Read Blocks": 0, - "Temp Written Blocks": 0 - } - ] + "Temp Written Blocks": 0 } ] } @@ -946,21 +882,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.14, + "Planning Time": 0.012, "Triggers": [], - "Execution Time": 7.168 + "Execution Time": 1.311 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2930.04, + "Startup Cost": 1487.53, + "Total Cost": 1487.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 9.149, - "Actual Total Time": 9.166, + "Actual Startup Time": 1.289, + "Actual Total Time": 1.293, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 404, @@ -979,12 +915,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2958.91, - "Plan Rows": 11599, + "Startup Cost": 1487.53, + "Total Cost": 1516.61, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 9.147, - "Actual Total Time": 9.156, + "Actual Startup Time": 1.289, + "Actual Total Time": 1.29, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -1006,26 +942,26 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Bitmap Heap Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 225.12, - "Total Cost": 2542.94, - "Plan Rows": 11599, + "Startup Cost": 0.29, + "Total Cost": 1099.46, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 6.961, - "Actual Total Time": 8.357, + "Actual Startup Time": 0.812, + "Actual Total Time": 1.084, "Actual Rows": 4000, "Actual Loops": 1, - "Recheck Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", + "Index Cond": "(chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 16000, - "Exact Heap Blocks": 385, - "Lossy Heap Blocks": 0, "Shared Hit Blocks": 404, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, @@ -1035,35 +971,7 @@ "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, - "Temp Written Blocks": 0, - "Plans": [ - { - "Node Type": "Bitmap Index Scan", - "Parent Relationship": "Outer", - "Parallel Aware": false, - "Async Capable": false, - "Index Name": "messages_history", - "Startup Cost": 0.0, - "Total Cost": 222.22, - "Plan Rows": 19990, - "Plan Width": 0, - "Actual Startup Time": 1.173, - "Actual Total Time": 1.174, - "Actual Rows": 20000, - "Actual Loops": 1, - "Index Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", - "Shared Hit Blocks": 19, - "Shared Read Blocks": 0, - "Shared Dirtied Blocks": 0, - "Shared Written Blocks": 0, - "Local Hit Blocks": 0, - "Local Read Blocks": 0, - "Local Dirtied Blocks": 0, - "Local Written Blocks": 0, - "Temp Read Blocks": 0, - "Temp Written Blocks": 0 - } - ] + "Temp Written Blocks": 0 } ] } @@ -1081,21 +989,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.176, + "Planning Time": 0.011, "Triggers": [], - "Execution Time": 9.21 + "Execution Time": 1.296 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2930.04, + "Startup Cost": 1487.53, + "Total Cost": 1487.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 6.349, - "Actual Total Time": 6.363, + "Actual Startup Time": 1.261, + "Actual Total Time": 1.264, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 404, @@ -1114,12 +1022,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 2929.91, - "Total Cost": 2958.91, - "Plan Rows": 11599, + "Startup Cost": 1487.53, + "Total Cost": 1516.61, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 6.347, - "Actual Total Time": 6.353, + "Actual Startup Time": 1.261, + "Actual Total Time": 1.262, "Actual Rows": 51, "Actual Loops": 1, "Sort Key": [ @@ -1141,26 +1049,26 @@ "Temp Written Blocks": 0, "Plans": [ { - "Node Type": "Bitmap Heap Scan", + "Node Type": "Index Scan", "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, + "Scan Direction": "Forward", + "Index Name": "messages_history", "Relation Name": "messages", "Alias": "messages", - "Startup Cost": 225.12, - "Total Cost": 2542.94, - "Plan Rows": 11599, + "Startup Cost": 0.29, + "Total Cost": 1099.46, + "Plan Rows": 11632, "Plan Width": 121, - "Actual Startup Time": 4.511, - "Actual Total Time": 5.601, + "Actual Startup Time": 0.777, + "Actual Total Time": 1.05, "Actual Rows": 4000, "Actual Loops": 1, - "Recheck Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", + "Index Cond": "(chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 16000, - "Exact Heap Blocks": 385, - "Lossy Heap Blocks": 0, "Shared Hit Blocks": 404, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, @@ -1170,35 +1078,7 @@ "Local Dirtied Blocks": 0, "Local Written Blocks": 0, "Temp Read Blocks": 0, - "Temp Written Blocks": 0, - "Plans": [ - { - "Node Type": "Bitmap Index Scan", - "Parent Relationship": "Outer", - "Parallel Aware": false, - "Async Capable": false, - "Index Name": "messages_history", - "Startup Cost": 0.0, - "Total Cost": 222.22, - "Plan Rows": 19990, - "Plan Width": 0, - "Actual Startup Time": 0.831, - "Actual Total Time": 0.831, - "Actual Rows": 20000, - "Actual Loops": 1, - "Index Cond": "(chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid)", - "Shared Hit Blocks": 19, - "Shared Read Blocks": 0, - "Shared Dirtied Blocks": 0, - "Shared Written Blocks": 0, - "Local Hit Blocks": 0, - "Local Read Blocks": 0, - "Local Dirtied Blocks": 0, - "Local Written Blocks": 0, - "Temp Read Blocks": 0, - "Temp Written Blocks": 0 - } - ] + "Temp Written Blocks": 0 } ] } @@ -1216,27 +1096,27 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.201, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 6.401 + "Execution Time": 1.267 } ] }, { "chat_messages": 200, - "median_execution_ms": 0.073, + "median_execution_ms": 0.02, "plans": [ { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.32, + "Startup Cost": 43.53, + "Total Cost": 43.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.059, - "Actual Total Time": 0.066, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.019, "Actual Rows": 40, "Actual Loops": 1, "Shared Hit Blocks": 7, @@ -1255,12 +1135,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.65, - "Plan Rows": 184, + "Startup Cost": 43.53, + "Total Cost": 44.05, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.058, - "Actual Total Time": 0.061, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.015, "Actual Rows": 40, "Actual Loops": 1, "Sort Key": [ @@ -1291,14 +1171,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.29, - "Total Cost": 384.05, - "Plan Rows": 184, + "Total Cost": 36.63, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.039, - "Actual Total Time": 0.049, + "Actual Startup Time": 0.01, + "Actual Total Time": 0.012, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "(chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid)", + "Index Cond": "(chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 160, @@ -1329,21 +1209,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.08, + "Planning Time": 0.012, "Triggers": [], - "Execution Time": 0.082 + "Execution Time": 0.021 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.32, + "Startup Cost": 43.53, + "Total Cost": 43.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.053, - "Actual Total Time": 0.06, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.018, "Actual Rows": 40, "Actual Loops": 1, "Shared Hit Blocks": 7, @@ -1362,12 +1242,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.65, - "Plan Rows": 184, + "Startup Cost": 43.53, + "Total Cost": 44.05, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.052, - "Actual Total Time": 0.055, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.016, "Actual Rows": 40, "Actual Loops": 1, "Sort Key": [ @@ -1398,14 +1278,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.29, - "Total Cost": 384.05, - "Plan Rows": 184, + "Total Cost": 36.63, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.036, - "Actual Total Time": 0.044, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.012, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "(chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid)", + "Index Cond": "(chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 160, @@ -1436,21 +1316,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.055, + "Planning Time": 0.014, "Triggers": [], - "Execution Time": 0.073 + "Execution Time": 0.02 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.32, + "Startup Cost": 43.53, + "Total Cost": 43.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.051, - "Actual Total Time": 0.058, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.018, "Actual Rows": 40, "Actual Loops": 1, "Shared Hit Blocks": 7, @@ -1469,12 +1349,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.65, - "Plan Rows": 184, + "Startup Cost": 43.53, + "Total Cost": 44.05, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.051, - "Actual Total Time": 0.054, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.015, "Actual Rows": 40, "Actual Loops": 1, "Sort Key": [ @@ -1505,14 +1385,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.29, - "Total Cost": 384.05, - "Plan Rows": 184, + "Total Cost": 36.63, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.033, - "Actual Total Time": 0.043, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.012, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "(chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid)", + "Index Cond": "(chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 160, @@ -1543,21 +1423,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.05, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 0.128 + "Execution Time": 0.02 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.32, + "Startup Cost": 43.53, + "Total Cost": 43.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.052, - "Actual Total Time": 0.06, + "Actual Startup Time": 0.026, + "Actual Total Time": 0.029, "Actual Rows": 40, "Actual Loops": 1, "Shared Hit Blocks": 7, @@ -1576,12 +1456,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.65, - "Plan Rows": 184, + "Startup Cost": 43.53, + "Total Cost": 44.05, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.051, - "Actual Total Time": 0.055, + "Actual Startup Time": 0.026, + "Actual Total Time": 0.027, "Actual Rows": 40, "Actual Loops": 1, "Sort Key": [ @@ -1612,14 +1492,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.29, - "Total Cost": 384.05, - "Plan Rows": 184, + "Total Cost": 36.63, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.034, - "Actual Total Time": 0.043, + "Actual Startup Time": 0.019, + "Actual Total Time": 0.022, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "(chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid)", + "Index Cond": "(chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 160, @@ -1650,21 +1530,21 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.059, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 0.073 + "Execution Time": 0.032 }, { "Plan": { "Node Type": "Limit", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.32, + "Startup Cost": 43.53, + "Total Cost": 43.66, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.049, - "Actual Total Time": 0.056, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.017, "Actual Rows": 40, "Actual Loops": 1, "Shared Hit Blocks": 7, @@ -1683,12 +1563,12 @@ "Parent Relationship": "Outer", "Parallel Aware": false, "Async Capable": false, - "Startup Cost": 390.19, - "Total Cost": 390.65, - "Plan Rows": 184, + "Startup Cost": 43.53, + "Total Cost": 44.05, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.048, - "Actual Total Time": 0.051, + "Actual Startup Time": 0.015, + "Actual Total Time": 0.016, "Actual Rows": 40, "Actual Loops": 1, "Sort Key": [ @@ -1719,14 +1599,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.29, - "Total Cost": 384.05, - "Plan Rows": 184, + "Total Cost": 36.63, + "Plan Rows": 207, "Plan Width": 121, - "Actual Startup Time": 0.032, - "Actual Total Time": 0.04, + "Actual Startup Time": 0.009, + "Actual Total Time": 0.012, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "(chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid)", + "Index Cond": "(chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid)", "Rows Removed by Index Recheck": 0, "Filter": "(ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid))", "Rows Removed by Filter": 160, @@ -1757,9 +1637,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.048, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 0.067 + "Execution Time": 0.02 } ] } @@ -1767,18 +1647,18 @@ "writes": [ { "rows": 1000, - "commit_ms": 51.328176000197345, - "wal_bytes": 254192 + "commit_ms": 12.854043999993792, + "wal_bytes": 232488 }, { "rows": 1000, - "commit_ms": 132.15779799998018, - "wal_bytes": 238088 + "commit_ms": 9.849200999980212, + "wal_bytes": 241648 }, { "rows": 1000, - "commit_ms": 88.45494599995618, - "wal_bytes": 245480 + "commit_ms": 9.713059999995721, + "wal_bytes": 241752 } ] }, @@ -1788,7 +1668,7 @@ "reads": [ { "chat_messages": 70000, - "median_execution_ms": 0.057, + "median_execution_ms": 0.011, "plans": [ { "Plan": { @@ -1796,11 +1676,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 34.54, + "Total Cost": 22.04, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.03, - "Actual Total Time": 0.05, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.011, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -1824,14 +1704,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6460.76, - "Plan Rows": 9655, + "Total Cost": 4175.07, + "Plan Rows": 9845, "Plan Width": 121, - "Actual Startup Time": 0.028, - "Actual Total Time": 0.041, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.009, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -1858,9 +1738,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.19, + "Planning Time": 0.013, "Triggers": [], - "Execution Time": 0.08 + "Execution Time": 0.015 }, { "Plan": { @@ -1868,11 +1748,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 34.54, + "Total Cost": 22.04, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.018, - "Actual Total Time": 0.037, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.008, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -1896,14 +1776,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6460.76, - "Plan Rows": 9655, + "Total Cost": 4175.07, + "Plan Rows": 9845, "Plan Width": 121, - "Actual Startup Time": 0.017, - "Actual Total Time": 0.028, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -1930,9 +1810,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.088, + "Planning Time": 0.011, "Triggers": [], - "Execution Time": 0.057 + "Execution Time": 0.012 }, { "Plan": { @@ -1940,11 +1820,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 34.54, + "Total Cost": 22.04, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.016, - "Actual Total Time": 0.035, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.008, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -1968,14 +1848,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6460.76, - "Plan Rows": 9655, + "Total Cost": 4175.07, + "Plan Rows": 9845, "Plan Width": 121, - "Actual Startup Time": 0.015, - "Actual Total Time": 0.027, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2002,9 +1882,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.089, + "Planning Time": 0.01, "Triggers": [], - "Execution Time": 0.053 + "Execution Time": 0.011 }, { "Plan": { @@ -2012,11 +1892,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 34.54, + "Total Cost": 22.04, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.018, - "Actual Total Time": 0.036, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.008, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2040,14 +1920,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6460.76, - "Plan Rows": 9655, + "Total Cost": 4175.07, + "Plan Rows": 9845, "Plan Width": 121, - "Actual Startup Time": 0.017, - "Actual Total Time": 0.028, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2074,9 +1954,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.14, + "Planning Time": 0.01, "Triggers": [], - "Execution Time": 0.055 + "Execution Time": 0.011 }, { "Plan": { @@ -2084,11 +1964,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 34.54, + "Total Cost": 22.04, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.018, - "Actual Total Time": 0.037, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.007, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2112,14 +1992,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6460.76, - "Plan Rows": 9655, + "Total Cost": 4175.07, + "Plan Rows": 9845, "Plan Width": 121, - "Actual Startup Time": 0.017, - "Actual Total Time": 0.028, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.005, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '1475545b-0118-40e4-959e-59045703e558'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '16d5e714-6c35-4ad8-8e2f-b097a33a346a'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.056+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2146,15 +2026,15 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.176, + "Planning Time": 0.009, "Triggers": [], - "Execution Time": 0.057 + "Execution Time": 0.01 } ] }, { "chat_messages": 20000, - "median_execution_ms": 0.072, + "median_execution_ms": 0.011, "plans": [ { "Plan": { @@ -2162,11 +2042,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 29.48, + "Total Cost": 19.2, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.049, - "Actual Total Time": 0.074, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.008, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2190,14 +2070,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6564.03, - "Plan Rows": 11517, + "Total Cost": 4277.68, + "Plan Rows": 11616, "Plan Width": 121, - "Actual Startup Time": 0.049, - "Actual Total Time": 0.061, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2224,9 +2104,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.153, + "Planning Time": 0.011, "Triggers": [], - "Execution Time": 0.095 + "Execution Time": 0.011 }, { "Plan": { @@ -2234,11 +2114,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 29.48, + "Total Cost": 19.2, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.018, - "Actual Total Time": 0.055, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.008, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2262,14 +2142,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6564.03, - "Plan Rows": 11517, + "Total Cost": 4277.68, + "Plan Rows": 11616, "Plan Width": 121, - "Actual Startup Time": 0.017, - "Actual Total Time": 0.046, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.006, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2296,9 +2176,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.071, + "Planning Time": 0.01, "Triggers": [], - "Execution Time": 0.072 + "Execution Time": 0.011 }, { "Plan": { @@ -2306,11 +2186,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 29.48, + "Total Cost": 19.2, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.017, - "Actual Total Time": 0.038, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.008, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2334,14 +2214,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6564.03, - "Plan Rows": 11517, + "Total Cost": 4277.68, + "Plan Rows": 11616, "Plan Width": 121, - "Actual Startup Time": 0.016, - "Actual Total Time": 0.03, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.005, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2368,9 +2248,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.061, + "Planning Time": 0.01, "Triggers": [], - "Execution Time": 0.052 + "Execution Time": 0.01 }, { "Plan": { @@ -2378,11 +2258,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 29.48, + "Total Cost": 19.2, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.014, - "Actual Total Time": 0.033, + "Actual Startup Time": 0.004, + "Actual Total Time": 0.01, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2406,14 +2286,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6564.03, - "Plan Rows": 11517, + "Total Cost": 4277.68, + "Plan Rows": 11616, "Plan Width": 121, - "Actual Startup Time": 0.014, - "Actual Total Time": 0.025, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.007, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2440,9 +2320,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.055, + "Planning Time": 0.011, "Triggers": [], - "Execution Time": 0.047 + "Execution Time": 0.013 }, { "Plan": { @@ -2450,11 +2330,11 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 29.48, + "Total Cost": 19.2, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.018, - "Actual Total Time": 0.143, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.007, "Actual Rows": 51, "Actual Loops": 1, "Shared Hit Blocks": 5, @@ -2478,14 +2358,14 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 6564.03, - "Plan Rows": 11517, + "Total Cost": 4277.68, + "Plan Rows": 11616, "Plan Width": 121, - "Actual Startup Time": 0.017, - "Actual Total Time": 0.135, + "Actual Startup Time": 0.003, + "Actual Total Time": 0.005, "Actual Rows": 51, "Actual Loops": 1, - "Index Cond": "((chat_id = '38cc764f-0e25-4cd9-8c22-46efb8b690da'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = 'be51a039-40ae-478f-98b6-16f33c11a842'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, "Shared Hit Blocks": 5, "Shared Read Blocks": 0, @@ -2512,15 +2392,15 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.155, + "Planning Time": 0.01, "Triggers": [], - "Execution Time": 0.161 + "Execution Time": 0.01 } ] }, { "chat_messages": 200, - "median_execution_ms": 0.065, + "median_execution_ms": 0.008, "plans": [ { "Plan": { @@ -2528,14 +2408,14 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 147.78, + "Total Cost": 92.88, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.027, - "Actual Total Time": 0.045, + "Actual Startup Time": 0.002, + "Actual Total Time": 0.006, "Actual Rows": 40, "Actual Loops": 1, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2556,16 +2436,16 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 532.08, - "Plan Rows": 184, + "Total Cost": 350.33, + "Plan Rows": 193, "Plan Width": 121, - "Actual Startup Time": 0.026, - "Actual Total Time": 0.038, + "Actual Startup Time": 0.002, + "Actual Total Time": 0.005, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "((chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2590,9 +2470,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.119, + "Planning Time": 0.011, "Triggers": [], - "Execution Time": 0.065 + "Execution Time": 0.009 }, { "Plan": { @@ -2600,14 +2480,14 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 147.78, + "Total Cost": 92.88, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.016, - "Actual Total Time": 0.032, + "Actual Startup Time": 0.002, + "Actual Total Time": 0.006, "Actual Rows": 40, "Actual Loops": 1, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2628,16 +2508,16 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 532.08, - "Plan Rows": 184, + "Total Cost": 350.33, + "Plan Rows": 193, "Plan Width": 121, - "Actual Startup Time": 0.015, - "Actual Total Time": 0.025, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.004, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "((chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2662,9 +2542,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.1, + "Planning Time": 0.01, "Triggers": [], - "Execution Time": 0.05 + "Execution Time": 0.008 }, { "Plan": { @@ -2672,14 +2552,14 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 147.78, + "Total Cost": 92.88, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.012, - "Actual Total Time": 0.028, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.006, "Actual Rows": 40, "Actual Loops": 1, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2700,16 +2580,16 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 532.08, - "Plan Rows": 184, + "Total Cost": 350.33, + "Plan Rows": 193, "Plan Width": 121, - "Actual Startup Time": 0.011, - "Actual Total Time": 0.021, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.004, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "((chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2734,9 +2614,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.064, + "Planning Time": 0.009, "Triggers": [], - "Execution Time": 0.042 + "Execution Time": 0.008 }, { "Plan": { @@ -2744,14 +2624,14 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 147.78, + "Total Cost": 92.88, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.016, - "Actual Total Time": 0.032, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.006, "Actual Rows": 40, "Actual Loops": 1, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2772,16 +2652,16 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 532.08, - "Plan Rows": 184, + "Total Cost": 350.33, + "Plan Rows": 193, "Plan Width": 121, - "Actual Startup Time": 0.015, - "Actual Total Time": 0.025, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.004, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "((chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2806,9 +2686,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.163, + "Planning Time": 0.009, "Triggers": [], - "Execution Time": 0.368 + "Execution Time": 0.008 }, { "Plan": { @@ -2816,14 +2696,14 @@ "Parallel Aware": false, "Async Capable": false, "Startup Cost": 0.42, - "Total Cost": 147.78, + "Total Cost": 92.88, "Plan Rows": 51, "Plan Width": 121, - "Actual Startup Time": 0.014, - "Actual Total Time": 0.035, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.006, "Actual Rows": 40, "Actual Loops": 1, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2844,16 +2724,16 @@ "Relation Name": "messages", "Alias": "messages", "Startup Cost": 0.42, - "Total Cost": 532.08, - "Plan Rows": 184, + "Total Cost": 350.33, + "Plan Rows": 193, "Plan Width": 121, - "Actual Startup Time": 0.013, - "Actual Total Time": 0.023, + "Actual Startup Time": 0.001, + "Actual Total Time": 0.004, "Actual Rows": 40, "Actual Loops": 1, - "Index Cond": "((chat_id = 'be0dc61b-8735-451c-9bee-09d564986b25'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", + "Index Cond": "((chat_id = '92295864-3ccd-4932-8aa1-9e7d9eaa73c0'::uuid) AND (ROW(created_at, id) > ROW('2026-01-01 00:00:00.00016+00'::timestamp with time zone, '00000000-0000-0000-0000-000000000000'::uuid)))", "Rows Removed by Index Recheck": 0, - "Shared Hit Blocks": 5, + "Shared Hit Blocks": 6, "Shared Read Blocks": 0, "Shared Dirtied Blocks": 0, "Shared Written Blocks": 0, @@ -2878,9 +2758,9 @@ "Temp Read Blocks": 0, "Temp Written Blocks": 0 }, - "Planning Time": 0.076, + "Planning Time": 0.009, "Triggers": [], - "Execution Time": 0.079 + "Execution Time": 0.008 } ] } @@ -2888,18 +2768,18 @@ "writes": [ { "rows": 1000, - "commit_ms": 186.78137000006245, - "wal_bytes": 326616 + "commit_ms": 10.444133999982341, + "wal_bytes": 319232 }, { "rows": 1000, - "commit_ms": 329.82252800002243, - "wal_bytes": 265320 + "commit_ms": 9.934636999986424, + "wal_bytes": 265152 }, { "rows": 1000, - "commit_ms": 473.14494300007937, - "wal_bytes": 322672 + "commit_ms": 9.918705000018235, + "wal_bytes": 311584 } ] } @@ -2912,55 +2792,55 @@ "messages": 100000, "sessions": 0 }, - "messages_sha256": "0f90589eece3910789d2eae40d5685c80cdf9f93e414aca19893851e85ffb071", + "messages_sha256": "8c3e317ab75daa8a5e97641eac51e3a349cffe2293bb83bc2ba22ce602cbf112", "selected_messages": [ { - "id": "00022a36-d2df-41d5-ab35-a9b2c71cd633", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.013387+00:00" + "id": "00000000-0000-0000-0000-000000000000", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x41004278787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00+00:00" }, { - "id": "0002979a-977b-4045-aa42-dfe668d8a498", - "chat_id": "38cc764f-0e25-4cd9-8c22-46efb8b690da", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.002863+00:00" + "id": "0000cf54-fd5c-4b78-9b83-5fdacc223d82", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.039523+00:00" }, { - "id": "7facae94-6022-46c6-9f65-d76df1d46d58", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.042234+00:00" + "id": "7fc2eae6-055d-4a9d-b3b7-4e09c7d735ea", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.037757+00:00" }, { - "id": "fffe2b8a-98d0-4c28-ae2a-08845ec95a49", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.035161+00:00" + "id": "fffe1a30-0346-4b72-b709-eb9c695c1993", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.040077+00:00" }, { - "id": "fffe8eae-d740-4296-b936-4f90a7bc140d", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.002345+00:00" + "id": "fffe9bca-2d05-4455-ab60-8d0d4d519df4", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.014042+00:00" } ] }, "backup": { "format": "pg_dump custom", - "bytes": 2655979, - "dump_seconds": 1.1019309590000024, - "bootstrap_seconds": 2.5880723749999994, - "restore_seconds": 1.742141042, - "restored_database": "restore_70a1c2c75a5c", - "source_container_id": "f8be6202d5e4", - "restore_container_id": "2db271910eb2", - "fresh_restore_volume": "mtusi-lab2-restore_70a1c2c75a5c-data", + "bytes": 2655198, + "dump_seconds": 0.2799740420000001, + "bootstrap_seconds": 0.8203773750000001, + "restore_seconds": 0.266880542, + "restored_database": "restore_4bc6680354a1", + "source_container_id": "07430ea862b6", + "restore_container_id": "aff2a0068a4c", + "fresh_restore_volume": "mtusi-lab2-restore_4bc6680354a1-data", "source_volume": [ "mtusi-lab2_postgres_data" ], @@ -2975,42 +2855,42 @@ "messages": 100000, "sessions": 0 }, - "messages_sha256": "0f90589eece3910789d2eae40d5685c80cdf9f93e414aca19893851e85ffb071", + "messages_sha256": "8c3e317ab75daa8a5e97641eac51e3a349cffe2293bb83bc2ba22ce602cbf112", "selected_messages": [ { - "id": "00022a36-d2df-41d5-ab35-a9b2c71cd633", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.013387+00:00" + "id": "00000000-0000-0000-0000-000000000000", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x41004278787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00+00:00" }, { - "id": "0002979a-977b-4045-aa42-dfe668d8a498", - "chat_id": "38cc764f-0e25-4cd9-8c22-46efb8b690da", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.002863+00:00" + "id": "0000cf54-fd5c-4b78-9b83-5fdacc223d82", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.039523+00:00" }, { - "id": "7facae94-6022-46c6-9f65-d76df1d46d58", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.042234+00:00" + "id": "7fc2eae6-055d-4a9d-b3b7-4e09c7d735ea", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.037757+00:00" }, { - "id": "fffe2b8a-98d0-4c28-ae2a-08845ec95a49", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.035161+00:00" + "id": "fffe1a30-0346-4b72-b709-eb9c695c1993", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.040077+00:00" }, { - "id": "fffe8eae-d740-4296-b936-4f90a7bc140d", - "chat_id": "1475545b-0118-40e4-959e-59045703e558", - "sender_id": "0bbe8371-c929-4ca0-9bde-82cfa960a2ac", - "text": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", - "created_at": "2026-01-01T00:00:00.002345+00:00" + "id": "fffe9bca-2d05-4455-ab60-8d0d4d519df4", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.014042+00:00" } ] } diff --git a/evidence/restart-after.json b/evidence/restart-after.json index 9169939d..b7ad4cf3 100644 --- a/evidence/restart-after.json +++ b/evidence/restart-after.json @@ -1,15 +1,15 @@ [ { "service": "api", - "container_id": "03414eeb9af4", - "started_at": "2026-10-23T06:53:58.384822282Z", + "container_id": "6b9b8576b1cd", + "started_at": "2026-10-23T09:20:44.739602998Z", "status": "running", "volumes": [] }, { "service": "postgres", - "container_id": "f8be6202d5e4", - "started_at": "2026-10-23T06:53:51.683479639Z", + "container_id": "07430ea862b6", + "started_at": "2026-10-23T09:20:41.28275813Z", "status": "running", "volumes": [ "mtusi-lab2_postgres_data" @@ -18,7 +18,7 @@ { "service": "redis", "container_id": "5fecf0c5edd1", - "started_at": "2026-10-23T06:53:51.383818051Z", + "started_at": "2026-10-23T09:20:41.313335565Z", "status": "running", "volumes": [ "b72dab0a9ef82932abd5655e09a614b5c99b3a7cef959426f05ad0a2ed7dbc79" diff --git a/evidence/restart-before.json b/evidence/restart-before.json index 9d77d458..204de2f3 100644 --- a/evidence/restart-before.json +++ b/evidence/restart-before.json @@ -1,15 +1,15 @@ [ { "service": "api", - "container_id": "03414eeb9af4", - "started_at": "2026-10-23T06:53:29.066897456Z", + "container_id": "6b9b8576b1cd", + "started_at": "2026-10-23T09:19:48.119673288Z", "status": "running", "volumes": [] }, { "service": "postgres", - "container_id": "f8be6202d5e4", - "started_at": "2026-10-23T06:53:24.074466953Z", + "container_id": "07430ea862b6", + "started_at": "2026-10-23T09:19:48.24800751Z", "status": "running", "volumes": [ "mtusi-lab2_postgres_data" @@ -18,7 +18,7 @@ { "service": "redis", "container_id": "5fecf0c5edd1", - "started_at": "2026-10-23T06:53:23.920707731Z", + "started_at": "2026-10-23T09:19:48.06854916Z", "status": "running", "volumes": [ "b72dab0a9ef82932abd5655e09a614b5c99b3a7cef959426f05ad0a2ed7dbc79" diff --git a/evidence/review-build.txt b/evidence/review-build.txt new file mode 100644 index 00000000..77202cd3 --- /dev/null +++ b/evidence/review-build.txt @@ -0,0 +1,75 @@ + Image mtusi-lab2-api Building +#1 [internal] load local bake definitions +#1 reading from stdin 656B done +#1 DONE 0.0s + +#2 [internal] load build definition from Dockerfile +#2 transferring dockerfile: 739B done +#2 DONE 0.0s + +#3 [internal] load metadata for docker.io/library/python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 +#3 DONE 0.0s + +#4 [internal] load .dockerignore +#4 transferring context: 132B done +#4 DONE 0.0s + +#5 [internal] load build context +#5 transferring context: 12.71kB done +#5 DONE 0.0s + +#6 [1/7] FROM docker.io/library/python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 +#6 resolve docker.io/library/python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 done +#6 DONE 0.0s + +#7 [4/7] COPY requirements.txt ./ +#7 CACHED + +#8 [2/7] WORKDIR /app +#8 CACHED + +#9 [3/7] RUN groupadd --gid 10001 app && useradd --uid 10001 --gid app --no-create-home app +#9 CACHED + +#10 [5/7] RUN pip install --no-cache-dir -r requirements.txt +#10 CACHED + +#11 [6/7] COPY src/ ./src/ +#11 DONE 0.0s + +#12 [7/7] COPY migrations/ ./migrations/ +#12 DONE 0.0s + +#13 exporting to image +#13 exporting layers 0.0s done +#13 exporting manifest sha256:4629666110b9f12ff95b707e9aafdd14712e1eacef6918851f271840c4a0a7dc done +#13 exporting config sha256:7c4d81b7399c8d2e57ab11ad9087b262cbdc4f79ce3298db7087079e530ce18a done +#13 exporting attestation manifest sha256:7e311d74504e1fe4150d50a931487c137683dce1c5ae5c6779c0493722acd01a done +#13 exporting manifest list sha256:0712b708d3a29530642a2c22dea53064fbfdfedc9537a18f3a04ba343e11da7f done +#13 naming to docker.io/library/mtusi-lab2-api:latest done +#13 unpacking to docker.io/library/mtusi-lab2-api:latest done +#13 DONE 0.1s + +#14 resolving provenance for metadata file +#14 DONE 0.0s + Image mtusi-lab2-api Built + Container mtusi-lab2-postgres-1 Recreate + Container mtusi-lab2-postgres-1 Recreated + Container mtusi-lab2-api-1 Recreate + Container mtusi-lab2-api-1 Recreated + Container mtusi-lab2-postgres-1 Starting + Container mtusi-lab2-redis-1 Starting + Container mtusi-lab2-postgres-1 Started + Container mtusi-lab2-redis-1 Started + Container mtusi-lab2-redis-1 Waiting + Container mtusi-lab2-postgres-1 Waiting + Container mtusi-lab2-redis-1 Healthy + Container mtusi-lab2-postgres-1 Healthy + Container mtusi-lab2-api-1 Starting + Container mtusi-lab2-api-1 Started + Container mtusi-lab2-api-1 Waiting + Container mtusi-lab2-postgres-1 Waiting + Container mtusi-lab2-redis-1 Waiting + Container mtusi-lab2-redis-1 Healthy + Container mtusi-lab2-postgres-1 Healthy + Container mtusi-lab2-api-1 Healthy diff --git a/evidence/review-clean-clone.txt b/evidence/review-clean-clone.txt new file mode 100644 index 00000000..57bb7e4f --- /dev/null +++ b/evidence/review-clean-clone.txt @@ -0,0 +1,116 @@ +Local configuration ready; secrets were not printed. + Image mtusi-lab2-review-50a92603-api Building +#1 [internal] load local bake definitions +#1 reading from stdin 704B done +#1 DONE 0.0s + +#2 resolving provenance for metadata file +#2 DONE 0.0s + +#3 [internal] load build definition from Dockerfile +#3 transferring dockerfile: 739B done +#3 DONE 0.0s + +#4 [internal] load metadata for docker.io/library/python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 +#4 DONE 0.0s + +#5 [internal] load .dockerignore +#5 transferring context: 132B done +#5 DONE 0.0s + +#6 [internal] load build context +#6 transferring context: 25.73kB done +#6 DONE 0.0s + +#7 [1/7] FROM docker.io/library/python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 +#7 resolve docker.io/library/python:3.12.8-slim-bookworm@sha256:2199a62885a12290dc9c5be3ca0681d367576ab7bf037da120e564723292a2f0 done +#7 DONE 0.0s + +#8 [2/7] WORKDIR /app +#8 CACHED + +#9 [4/7] COPY requirements.txt ./ +#9 CACHED + +#10 [5/7] RUN pip install --no-cache-dir -r requirements.txt +#10 CACHED + +#11 [6/7] COPY src/ ./src/ +#11 CACHED + +#12 [3/7] RUN groupadd --gid 10001 app && useradd --uid 10001 --gid app --no-create-home app +#12 CACHED + +#13 [7/7] COPY migrations/ ./migrations/ +#13 CACHED + +#14 exporting to image +#14 exporting layers done +#14 exporting manifest sha256:9de8694da45da73001c72c27f49f41b2b32dda6f170fb0ce738ced563c2c9471 done +#14 exporting config sha256:21388fc537a563dea4b9d14946bc95036d2ca3727ebed78cdeb410843e7f3700 done +#14 exporting attestation manifest sha256:ced1e33e702d25de0036f12d77f8ba1e49335255d54c60a9de74a012000fc609 done +#14 exporting manifest list sha256:6e728a75c92839d45b87038fbbe85f2db96e887e3614496fcc34a4ede2824c42 done +#14 naming to docker.io/library/mtusi-lab2-review-50a92603-api:latest done +#14 unpacking to docker.io/library/mtusi-lab2-review-50a92603-api:latest done +#14 DONE 0.0s + Image mtusi-lab2-review-50a92603-api Built + Network mtusi-lab2-review-50a92603_default Creating + Network mtusi-lab2-review-50a92603_default Created + Volume mtusi-lab2-review-50a92603_postgres_data Creating + Volume mtusi-lab2-review-50a92603_postgres_data Created + Container mtusi-lab2-review-50a92603-redis-1 Creating + Container mtusi-lab2-review-50a92603-postgres-1 Creating + Container mtusi-lab2-review-50a92603-postgres-1 Created + Container mtusi-lab2-review-50a92603-redis-1 Created + Container mtusi-lab2-review-50a92603-api-1 Creating + Container mtusi-lab2-review-50a92603-api-1 Created + Container mtusi-lab2-review-50a92603-postgres-1 Starting + Container mtusi-lab2-review-50a92603-redis-1 Starting + Container mtusi-lab2-review-50a92603-postgres-1 Started + Container mtusi-lab2-review-50a92603-redis-1 Started + Container mtusi-lab2-review-50a92603-postgres-1 Waiting + Container mtusi-lab2-review-50a92603-redis-1 Waiting + Container mtusi-lab2-review-50a92603-postgres-1 Healthy + Container mtusi-lab2-review-50a92603-redis-1 Healthy + Container mtusi-lab2-review-50a92603-api-1 Starting + Container mtusi-lab2-review-50a92603-api-1 Started + Container mtusi-lab2-review-50a92603-api-1 Waiting + Container mtusi-lab2-review-50a92603-postgres-1 Waiting + Container mtusi-lab2-review-50a92603-redis-1 Waiting + Container mtusi-lab2-review-50a92603-redis-1 Healthy + Container mtusi-lab2-review-50a92603-postgres-1 Healthy + Container mtusi-lab2-review-50a92603-api-1 Healthy +python3 scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +python3 tests/smoke.py --base-url "http://127.0.0.1:18086" +PASS: lab2 public API scenario; infrastructure and grading evidence remain separate. +BASE_URL="http://127.0.0.1:18086" python3 -m unittest discover -s student-tests -p test_api.py -v +test_concurrent_messages_and_pagination (test_api.APIContract) ... ok +test_cursor_scope_and_validation (test_api.APIContract) ... ok +test_foreign_chat (test_api.APIContract) ... ok +test_invalid_chat_creation (test_api.APIContract) ... ok +test_malformed_json_and_extra_fields (test_api.APIContract) ... ok +test_registration_race (test_api.APIContract) ... ok +test_unicode_limits (test_api.APIContract) ... ok +test_unicode_nul_round_trip (test_api.APIContract) ... ok +test_unicode_password_basic_and_logout (test_api.APIContract) ... ok + +---------------------------------------------------------------------- +Ran 9 tests in 3.405s + +OK +PASS: clean local clone, fresh Compose project/volume, migrations 001+002, public smoke and all nine student tests. + Container mtusi-lab2-review-50a92603-api-1 Stopping + Container mtusi-lab2-review-50a92603-api-1 Stopped + Container mtusi-lab2-review-50a92603-api-1 Removing + Container mtusi-lab2-review-50a92603-api-1 Removed + Container mtusi-lab2-review-50a92603-postgres-1 Stopping + Container mtusi-lab2-review-50a92603-redis-1 Stopping + Container mtusi-lab2-review-50a92603-redis-1 Stopped + Container mtusi-lab2-review-50a92603-redis-1 Removing + Container mtusi-lab2-review-50a92603-redis-1 Removed + Container mtusi-lab2-review-50a92603-postgres-1 Stopped + Container mtusi-lab2-review-50a92603-postgres-1 Removing + Container mtusi-lab2-review-50a92603-postgres-1 Removed + Network mtusi-lab2-review-50a92603_default Removing + Network mtusi-lab2-review-50a92603_default Removed diff --git a/evidence/review-dependencies.txt b/evidence/review-dependencies.txt new file mode 100644 index 00000000..40e39c38 --- /dev/null +++ b/evidence/review-dependencies.txt @@ -0,0 +1,16 @@ +python3 student-tests/dependencies.py + Container mtusi-lab2-redis-1 Stopping + Container mtusi-lab2-redis-1 Stopped + Container mtusi-lab2-redis-1 Starting + Container mtusi-lab2-redis-1 Started + Container mtusi-lab2-redis-1 Waiting + Container mtusi-lab2-redis-1 Healthy + Container mtusi-lab2-postgres-1 Stopping + Container mtusi-lab2-postgres-1 Stopped + Container mtusi-lab2-postgres-1 Starting + Container mtusi-lab2-postgres-1 Started + Container mtusi-lab2-postgres-1 Waiting + Container mtusi-lab2-postgres-1 Healthy + Container mtusi-lab2-expiry-29f426d1 Creating + Container mtusi-lab2-expiry-29f426d1 Created +PASS: rollback, real Redis TTL/cache, Redis outage, PostgreSQL outage/recovery and session expiry. diff --git a/evidence/review-persistence.txt b/evidence/review-persistence.txt new file mode 100644 index 00000000..933c59c7 --- /dev/null +++ b/evidence/review-persistence.txt @@ -0,0 +1,3 @@ +python3 tests/resilience.py --mode persistence --action-script "scripts/restart.sh" --base-url "http://localhost:8080" +Executing explicit persistence hook; hook output suppressed to avoid leaking secrets. +PASS: persistence preserved confirmed data and existing session. Hook scope needs operator evidence. diff --git a/evidence/review-research.txt b/evidence/review-research.txt new file mode 100644 index 00000000..cb7c0fff --- /dev/null +++ b/evidence/review-research.txt @@ -0,0 +1,21 @@ +Fresh restore run 1 + Container mtusi-lab2-api-run-2c95cff15d63 Creating + Container mtusi-lab2-api-run-2c95cff15d63 Created + Container mtusi-lab2-api-run-dd11ae88dd79 Creating + Container mtusi-lab2-api-run-dd11ae88dd79 Created +PASS: 100000 messages; two indexes; write costs; backup/restore counts, samples and full checksum match. +Backup seconds: 0.281 Restore seconds: 0.268 +Fresh restore run 2 + Container mtusi-lab2-api-run-60ccc9d0034f Creating + Container mtusi-lab2-api-run-60ccc9d0034f Created + Container mtusi-lab2-api-run-2292e9ea796b Creating + Container mtusi-lab2-api-run-2292e9ea796b Created +PASS: 100000 messages; two indexes; write costs; backup/restore counts, samples and full checksum match. +Backup seconds: 0.304 Restore seconds: 0.289 +Fresh restore run 3 + Container mtusi-lab2-api-run-f8267d018f9d Creating + Container mtusi-lab2-api-run-f8267d018f9d Created + Container mtusi-lab2-api-run-b73f035b1b8c Creating + Container mtusi-lab2-api-run-b73f035b1b8c Created +PASS: 100000 messages; two indexes; write costs; backup/restore counts, samples and full checksum match. +Backup seconds: 0.28 Restore seconds: 0.267 diff --git a/evidence/review-restore-runs.json b/evidence/review-restore-runs.json new file mode 100644 index 00000000..3a885385 --- /dev/null +++ b/evidence/review-restore-runs.json @@ -0,0 +1,209 @@ +[ + { + "run": 1, + "backup": { + "format": "pg_dump custom", + "bytes": 2655885, + "dump_seconds": 0.2805722919999998, + "bootstrap_seconds": 0.8350770000000001, + "restore_seconds": 0.2675151250000001, + "restored_database": "restore_8e3b0298c2c4", + "source_container_id": "07430ea862b6", + "restore_container_id": "db6ae0750cc8", + "fresh_restore_volume": "mtusi-lab2-restore_8e3b0298c2c4-data", + "source_volume": [ + "mtusi-lab2_postgres_data" + ], + "matching_counts": true, + "matching_all_messages_sha256": true, + "matching_selected_messages": true, + "restored_snapshot": { + "counts": { + "users": 1, + "chats": 10, + "chat_members": 10, + "messages": 100000, + "sessions": 0 + }, + "messages_sha256": "3c38a0e32acafed71651826488fb514af7371e7d43bbfeb08f73aed17d68ea4f", + "selected_messages": [ + { + "id": "00000000-0000-0000-0000-000000000000", + "chat_id": "12a8a7fe-93db-49a5-a5bf-f19f24392ffd", + "sender_id": "538d79bc-a7f0-4e96-8698-4ab577ed37c9", + "text": "\\x41004278787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00+00:00" + }, + { + "id": "0000234c-4b36-4929-a3d8-31b88d3944ed", + "chat_id": "12a8a7fe-93db-49a5-a5bf-f19f24392ffd", + "sender_id": "538d79bc-a7f0-4e96-8698-4ab577ed37c9", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.033386+00:00" + }, + { + "id": "801769f9-9185-4fef-996a-754fe04331e8", + "chat_id": "5d7a1ad8-8b31-4976-971a-eee92058b8e1", + "sender_id": "538d79bc-a7f0-4e96-8698-4ab577ed37c9", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.002124+00:00" + }, + { + "id": "ffff5474-757f-457f-8bd5-894401da2910", + "chat_id": "12a8a7fe-93db-49a5-a5bf-f19f24392ffd", + "sender_id": "538d79bc-a7f0-4e96-8698-4ab577ed37c9", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.059892+00:00" + }, + { + "id": "ffffa45b-75ea-4839-a5bd-fb0a85ba0d29", + "chat_id": "12a8a7fe-93db-49a5-a5bf-f19f24392ffd", + "sender_id": "538d79bc-a7f0-4e96-8698-4ab577ed37c9", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.048116+00:00" + } + ] + } + }, + "messages": 100000, + "nul_sample_verified": true + }, + { + "run": 2, + "backup": { + "format": "pg_dump custom", + "bytes": 2654444, + "dump_seconds": 0.303841, + "bootstrap_seconds": 0.8235868330000002, + "restore_seconds": 0.28861237500000003, + "restored_database": "restore_dc75cd9655c0", + "source_container_id": "07430ea862b6", + "restore_container_id": "9a2e73441fcf", + "fresh_restore_volume": "mtusi-lab2-restore_dc75cd9655c0-data", + "source_volume": [ + "mtusi-lab2_postgres_data" + ], + "matching_counts": true, + "matching_all_messages_sha256": true, + "matching_selected_messages": true, + "restored_snapshot": { + "counts": { + "users": 1, + "chats": 10, + "chat_members": 10, + "messages": 100000, + "sessions": 0 + }, + "messages_sha256": "27b5a42196b56676462b626f38f28da114bcc7da0d4c584d4239e0286df4ab4b", + "selected_messages": [ + { + "id": "00000000-0000-0000-0000-000000000000", + "chat_id": "a8efc6c4-bc38-4460-862a-01a5b31db242", + "sender_id": "410288f9-4285-4b2c-9d5d-8ff651324300", + "text": "\\x41004278787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00+00:00" + }, + { + "id": "00003164-09c1-41f2-be94-4c59dac29663", + "chat_id": "a8efc6c4-bc38-4460-862a-01a5b31db242", + "sender_id": "410288f9-4285-4b2c-9d5d-8ff651324300", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.048618+00:00" + }, + { + "id": "7f75439b-8443-451b-bd19-2fe5e0592b3b", + "chat_id": "a8efc6c4-bc38-4460-862a-01a5b31db242", + "sender_id": "410288f9-4285-4b2c-9d5d-8ff651324300", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.013799+00:00" + }, + { + "id": "ffff6737-a2c0-479f-bc93-c68bdf9ceea7", + "chat_id": "f7079b99-bdba-46ac-a651-1c2a451fcad2", + "sender_id": "410288f9-4285-4b2c-9d5d-8ff651324300", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.017859+00:00" + }, + { + "id": "ffffd4f9-50c9-4e50-a320-2b4afa0e0dec", + "chat_id": "a8efc6c4-bc38-4460-862a-01a5b31db242", + "sender_id": "410288f9-4285-4b2c-9d5d-8ff651324300", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.068415+00:00" + } + ] + } + }, + "messages": 100000, + "nul_sample_verified": true + }, + { + "run": 3, + "backup": { + "format": "pg_dump custom", + "bytes": 2655198, + "dump_seconds": 0.2799740420000001, + "bootstrap_seconds": 0.8203773750000001, + "restore_seconds": 0.266880542, + "restored_database": "restore_4bc6680354a1", + "source_container_id": "07430ea862b6", + "restore_container_id": "aff2a0068a4c", + "fresh_restore_volume": "mtusi-lab2-restore_4bc6680354a1-data", + "source_volume": [ + "mtusi-lab2_postgres_data" + ], + "matching_counts": true, + "matching_all_messages_sha256": true, + "matching_selected_messages": true, + "restored_snapshot": { + "counts": { + "users": 1, + "chats": 10, + "chat_members": 10, + "messages": 100000, + "sessions": 0 + }, + "messages_sha256": "8c3e317ab75daa8a5e97641eac51e3a349cffe2293bb83bc2ba22ce602cbf112", + "selected_messages": [ + { + "id": "00000000-0000-0000-0000-000000000000", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x41004278787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00+00:00" + }, + { + "id": "0000cf54-fd5c-4b78-9b83-5fdacc223d82", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.039523+00:00" + }, + { + "id": "7fc2eae6-055d-4a9d-b3b7-4e09c7d735ea", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.037757+00:00" + }, + { + "id": "fffe1a30-0346-4b72-b709-eb9c695c1993", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.040077+00:00" + }, + { + "id": "fffe9bca-2d05-4455-ab60-8d0d4d519df4", + "chat_id": "16d5e714-6c35-4ad8-8e2f-b097a33a346a", + "sender_id": "f34b3772-5504-4f6f-861b-f22d07f10181", + "text": "\\x78787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878787878", + "created_at": "2026-01-01T00:00:00.014042+00:00" + } + ] + } + }, + "messages": 100000, + "nul_sample_verified": true + } +] diff --git a/evidence/review-tests.txt b/evidence/review-tests.txt new file mode 100644 index 00000000..cb8609fe --- /dev/null +++ b/evidence/review-tests.txt @@ -0,0 +1,21 @@ +../.venv/bin/python scripts/check_contract.py +PASS: offline skeleton structure, local refs and Python syntax; application NOT tested. +../.venv/bin/python scripts/validate_openapi.py +PASS: full OpenAPI 3.1 and JSON Schema validation; application NOT tested. +../.venv/bin/python tests/smoke.py --base-url "http://localhost:8080" +PASS: lab2 public API scenario; infrastructure and grading evidence remain separate. +BASE_URL="http://localhost:8080" ../.venv/bin/python -m unittest discover -s student-tests -p test_api.py -v +test_concurrent_messages_and_pagination (test_api.APIContract.test_concurrent_messages_and_pagination) ... ok +test_cursor_scope_and_validation (test_api.APIContract.test_cursor_scope_and_validation) ... ok +test_foreign_chat (test_api.APIContract.test_foreign_chat) ... ok +test_invalid_chat_creation (test_api.APIContract.test_invalid_chat_creation) ... ok +test_malformed_json_and_extra_fields (test_api.APIContract.test_malformed_json_and_extra_fields) ... ok +test_registration_race (test_api.APIContract.test_registration_race) ... ok +test_unicode_limits (test_api.APIContract.test_unicode_limits) ... ok +test_unicode_nul_round_trip (test_api.APIContract.test_unicode_nul_round_trip) ... ok +test_unicode_password_basic_and_logout (test_api.APIContract.test_unicode_password_basic_and_logout) ... ok + +---------------------------------------------------------------------- +Ran 9 tests in 2.631s + +OK diff --git a/evidence/review-unicode-persistence.txt b/evidence/review-unicode-persistence.txt new file mode 100644 index 00000000..ab689471 --- /dev/null +++ b/evidence/review-unicode-persistence.txt @@ -0,0 +1,7 @@ + Container mtusi-lab2-postgres-1 Restarting + Container mtusi-lab2-redis-1 Restarting + Container mtusi-lab2-api-1 Restarting + Container mtusi-lab2-redis-1 Started + Container mtusi-lab2-api-1 Started + Container mtusi-lab2-postgres-1 Started +PASS: U+0000 and literal backslash-u0000 preserved in display_name/title/text after API/PostgreSQL/Redis restart; original Bearer still valid. diff --git a/migrations/002_unicode_nul.sql b/migrations/002_unicode_nul.sql new file mode 100644 index 00000000..224cda0d --- /dev/null +++ b/migrations/002_unicode_nul.sql @@ -0,0 +1,17 @@ +-- PostgreSQL TEXT cannot contain U+0000. Store validated UTF-8 losslessly in BYTEA. +-- API validation keeps the contract's code-point limits; these bounds cap bytes. +ALTER TABLE users + DROP CONSTRAINT users_display_name_check + , ALTER COLUMN display_name TYPE BYTEA USING convert_to(display_name, 'UTF8') + , ADD CONSTRAINT users_display_name_bytes CHECK (octet_length(display_name) BETWEEN 1 AND 400) +; +ALTER TABLE chats + DROP CONSTRAINT chats_title_check + , ALTER COLUMN title TYPE BYTEA USING convert_to(title, 'UTF8') + , ADD CONSTRAINT chats_title_bytes CHECK (octet_length(title) BETWEEN 1 AND 400) +; +ALTER TABLE messages + DROP CONSTRAINT messages_text_check + , ALTER COLUMN text TYPE BYTEA USING convert_to(text, 'UTF8') + , ADD CONSTRAINT messages_text_bytes CHECK (octet_length(text) BETWEEN 1 AND 16000) +; diff --git a/src/postgres.py b/src/postgres.py index f7b76b84..d7f2f384 100644 --- a/src/postgres.py +++ b/src/postgres.py @@ -26,7 +26,7 @@ def setting(name): def public(row): - return {k: (str(v) if isinstance(v, uuid.UUID) else v.isoformat(timespec='microseconds').replace('+00:00', 'Z') if isinstance(v, dt.datetime) else v) for k, v in row.items() if k != 'password_hash'} + return {k: (v.decode('utf-8') if isinstance(v, bytes) else str(v) if isinstance(v, uuid.UUID) else v.isoformat(timespec='microseconds').replace('+00:00', 'Z') if isinstance(v, dt.datetime) else v) for k, v in row.items() if k != 'password_hash'} def password_hash(password, salt=None): @@ -97,7 +97,7 @@ class Store: INSERT INTO users (id, username, display_name, password_hash) VALUES (%s, %s, %s, %s) RETURNING id, username, display_name, created_at - ''', (uuid.uuid4(), name, display, hashed)).fetchone() + ''', (uuid.uuid4(), name, display.encode('utf-8'), hashed)).fetchone() return public(row) def login(self, headers): @@ -194,7 +194,7 @@ class Store: invalid() with self.connection() as conn: chat_id = uuid.uuid4() - conn.execute('INSERT INTO chats (id, title) VALUES (%s, %s)', (chat_id, title)) + conn.execute('INSERT INTO chats (id, title) VALUES (%s, %s)', (chat_id, title.encode('utf-8'))) # Checking after INSERT exercises rollback of the whole composite operation. found = conn.execute('SELECT id FROM users WHERE 1=1 AND id = ANY(%s::uuid[])', (members,)).fetchall() if len(found) != len(members): @@ -236,7 +236,7 @@ class Store: INSERT INTO messages (id, chat_id, sender_id, text, created_at) VALUES (%s, %s, %s, %s, %s) RETURNING id, chat_id, sender_id, text, created_at - ''', (uuid.uuid4(), chat_id, actor['id'], content, stamp)).fetchone() + ''', (uuid.uuid4(), chat_id, actor['id'], content.encode('utf-8'), stamp)).fetchone() return public(row) def history(self, actor, chat_id, limit, cursor, scope): diff --git a/student-tests/index_study.py b/student-tests/index_study.py index 1329a95f..ac3d8dbd 100644 --- a/student-tests/index_study.py +++ b/student-tests/index_study.py @@ -43,19 +43,23 @@ def main(): with psycopg.connect(url, autocommit=True) as admin: admin.execute(sql.SQL('CREATE DATABASE {}').format(sql.Identifier(database))) conn = psycopg.connect(make_conninfo(url, dbname=database)) - conn.execute((ROOT / 'migrations/001_initial.sql').read_text()) + for migration in sorted((ROOT / 'migrations').glob('*.sql')): + conn.execute(migration.read_text()) user = uuid.uuid4() - conn.execute('INSERT INTO users (id, username, display_name, password_hash) VALUES (%s, %s, %s, %s)', (user, 'research_user', 'Synthetic', 'not-an-authenticatable-password')) + conn.execute('INSERT INTO users (id, username, display_name, password_hash) VALUES (%s, %s, %s, %s)', (user, 'research_user', b'Synthetic', 'not-an-authenticatable-password')) sizes = [70000, 20000, 5000, 2000, 1000, 800, 500, 300, 200, 200] chats = [uuid.uuid4() for _ in sizes] base = dt.datetime(2026, 1, 1, tzinfo=dt.timezone.utc) for chat in chats: - conn.execute('INSERT INTO chats (id, title) VALUES (%s, %s)', (chat, 'Synthetic')) + conn.execute('INSERT INTO chats (id, title) VALUES (%s, %s)', (chat, b'Synthetic')) conn.execute('INSERT INTO chat_members (chat_id, user_id) VALUES (%s, %s)', (chat, user)) with conn.cursor().copy('COPY messages (id, chat_id, sender_id, text, created_at) FROM STDIN') as copy: for chat, count in zip(chats, sizes): for i in range(count): - copy.write_row((uuid.uuid4(), chat, user, 'x' * 64, base + dt.timedelta(microseconds=i))) + first = chat == chats[0] and i == 0 + mid = uuid.UUID(int=0) if first else uuid.uuid4() + content = b'A\x00B' + b'x' * 61 if first else b'x' * 64 + copy.write_row((mid, chat, user, content, base + dt.timedelta(microseconds=i))) conn.commit() results = [] query = ''' @@ -93,7 +97,7 @@ def main(): started = time.perf_counter() with conn.cursor().copy('COPY messages (id, chat_id, sender_id, text, created_at) FROM STDIN') as copy: for i, mid in enumerate(ids): - copy.write_row((mid, chats[0], user, 'write-cost', base + dt.timedelta(seconds=1, microseconds=i))) + copy.write_row((mid, chats[0], user, b'write-cost', base + dt.timedelta(seconds=1, microseconds=i))) conn.commit() elapsed = (time.perf_counter() - started) * 1000 wal = conn.execute('SELECT pg_wal_lsn_diff(pg_current_wal_insert_lsn(), %s::pg_lsn)', (before,)).fetchone()[0] @@ -104,6 +108,7 @@ def main(): results.append(dict(variant=variant, index_bytes=index_size, reads=reads, writes=writes)) captured = snapshot(conn) assert captured['counts']['messages'] == 100000 + assert captured['selected_messages'][0]['text'] == '\\x' + (b'A\x00B' + b'x' * 61).hex() version = conn.execute('SELECT version()').fetchone()[0] conn.close() print(json.dumps(dict(database=database, postgresql=version, sizes=sizes, query=query, repeats=5, results=results, snapshot=captured))) diff --git a/student-tests/research.py b/student-tests/research.py index 7d845119..6c1b23c1 100644 --- a/student-tests/research.py +++ b/student-tests/research.py @@ -34,13 +34,15 @@ started_bootstrap = time.perf_counter() restore_id = subprocess.check_output(['docker', 'run', '-d', '--name', restore_container, '--network', network, '--cpus=1', '--memory=512m', '-e', 'POSTGRES_USER=messenger', '-e', 'POSTGRES_DB=' + restore, '-e', 'POSTGRES_PASSWORD_FILE=/run/secrets/postgres_password', '--mount', 'type=volume,src=' + restore_volume + ',dst=/var/lib/postgresql/data', '--mount', 'type=bind,src=' + str(ROOT / 'secrets/postgres_password') + ',dst=/run/secrets/postgres_password,readonly', image], text=True).strip() try: deadline = time.monotonic() + 45 - while subprocess.run(['docker', 'exec', restore_container, 'pg_isready', '-U', 'messenger', '-d', restore], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode: + # The entrypoint's temporary init server accepts Unix sockets only. + # TCP becomes ready only after initialization has finished and it is replaced. + while subprocess.run(['docker', 'exec', restore_container, 'pg_isready', '-h', '127.0.0.1', '-U', 'messenger', '-d', restore], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode: assert time.monotonic() < deadline, 'new PostgreSQL did not become ready' time.sleep(0.3) bootstrap_seconds = time.perf_counter() - started_bootstrap started = time.perf_counter() with backup.open('rb') as data: - subprocess.run(['docker', 'exec', '-i', restore_container, 'pg_restore', '-U', 'messenger', '--no-owner', '--exit-on-error', '-d', restore], stdin=data, check=True) + subprocess.run(['docker', 'exec', '-i', restore_container, 'pg_restore', '-h', '127.0.0.1', '-U', 'messenger', '--no-owner', '--exit-on-error', '-d', restore], stdin=data, check=True) restore_seconds = time.perf_counter() - started verified = json.loads(subprocess.check_output(RUN + ['-e', 'RESEARCH_DATABASE=' + restore, '-e', 'RESEARCH_HOST=' + restore_container, 'api', 'python', 'student-tests/index_study.py', '--verify'], text=True)) finally: diff --git a/student-tests/test_api.py b/student-tests/test_api.py index 2be98ef5..611eadcc 100644 --- a/student-tests/test_api.py +++ b/student-tests/test_api.py @@ -29,6 +29,28 @@ class APIContract(unittest.TestCase): self.assertEqual(result['text'], '👩' * 4000) self.client.call('POST', self.path + '/messages', 400, actor=self.alice, body={'text': '👩' * 4001}) + def test_unicode_nul_round_trip(self): + import base64 + value = 'A\x00B\\u0000👩' + registration = dict(self.alice['registration'], username='nul_' + uuid.uuid4().hex[:20], display_name=value) + user = self.client.call('POST', '/api/v1/users', 201, body=registration, schema='User')['json'] + self.assertEqual(user['display_name'], value) + credential = base64.b64encode((registration['username'] + ':' + registration['password']).encode()).decode() + session = self.client.call('POST', '/api/v1/auth/sessions', 201, headers={'Authorization': 'Basic ' + credential}, schema='Session')['json'] + self.assertEqual(session['user'], user) + actor = {'id': user['id'], 'token': session['token']} + # Exercise the database path and then the Redis profile cache. + for _ in range(2): + self.assertEqual(self.client.call('GET', '/api/v1/users/me', actor=actor, schema='User')['json'], user) + chat = self.client.call('POST', '/api/v1/chats', 201, actor=actor, body={'title': value, 'member_ids': [actor['id']]}, schema='Chat')['json'] + self.assertEqual(chat['title'], value) + self.assertEqual(self.client.call('GET', '/api/v1/chats/' + chat['id'], actor=actor, schema='Chat')['json'], chat) + contents = [value, '\x00' * 4000, '👩' * 3999 + '\x00'] + for content in contents: + self.assertEqual(self.client.message(actor, chat, content)['json']['text'], content) + history = self.client.call('GET', '/api/v1/chats/' + chat['id'] + '/messages', actor=actor, schema='MessagePage')['json'] + self.assertEqual([message['text'] for message in history['items']], contents) + def test_foreign_chat(self): for suffix in ('', '/messages'): self.client.call('GET', self.path + suffix, 404, actor=self.eve)