From bae020d5a7a6c9d09cbf707c87bc0f42e9112dfc Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 26 Jun 2016 11:00:39 -0700 Subject: [PATCH] DB: add mailboxes.for_nameplate Also add a few indexes to make get_stats() less expensive --- src/wormhole/server/db-schemas/upgrade-to-v3.sql | 7 +++++-- src/wormhole/server/db-schemas/v3.sql | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/wormhole/server/db-schemas/upgrade-to-v3.sql b/src/wormhole/server/db-schemas/upgrade-to-v3.sql index 4919206..b613f8f 100644 --- a/src/wormhole/server/db-schemas/upgrade-to-v3.sql +++ b/src/wormhole/server/db-schemas/upgrade-to-v3.sql @@ -34,7 +34,8 @@ CREATE TABLE `mailboxes` ( `app_id` VARCHAR, `id` VARCHAR PRIMARY KEY, - `updated` INTEGER -- time of last activity, used for pruning + `updated` INTEGER, -- time of last activity, used for pruning + `for_nameplate` BOOLEAN -- allocated for a nameplate, not standalone ); CREATE INDEX `mailboxes_idx` ON `mailboxes` (`app_id`, `id`); @@ -43,7 +44,7 @@ CREATE TABLE `mailbox_sides` `mailbox_id` REFERENCES `mailboxes`(`id`), `opened` BOOLEAN, -- True after open(), False after close() `side` VARCHAR, - `added` INTEGER, -- time when this side first claimed the nameplate + `added` INTEGER, -- time when this side first opened the mailbox `mood` VARCHAR ); @@ -59,6 +60,8 @@ CREATE TABLE `messages` ); CREATE INDEX `messages_idx` ON `messages` (`app_id`, `mailbox_id`); +CREATE INDEX `mailbox_usage_result_idx` ON `mailbox_usage` (`result`); +CREATE INDEX `transit_usage_result_idx` ON `transit_usage` (`result`); DELETE FROM `version`; INSERT INTO `version` (`version`) VALUES (3); diff --git a/src/wormhole/server/db-schemas/v3.sql b/src/wormhole/server/db-schemas/v3.sql index 1274a76..751d0ed 100644 --- a/src/wormhole/server/db-schemas/v3.sql +++ b/src/wormhole/server/db-schemas/v3.sql @@ -39,7 +39,8 @@ CREATE TABLE `mailboxes` ( `app_id` VARCHAR, `id` VARCHAR PRIMARY KEY, - `updated` INTEGER -- time of last activity, used for pruning + `updated` INTEGER, -- time of last activity, used for pruning + `for_nameplate` BOOLEAN -- allocated for a nameplate, not standalone ); CREATE INDEX `mailboxes_idx` ON `mailboxes` (`app_id`, `id`); @@ -48,7 +49,7 @@ CREATE TABLE `mailbox_sides` `mailbox_id` REFERENCES `mailboxes`(`id`), `opened` BOOLEAN, -- True after open(), False after close() `side` VARCHAR, - `added` INTEGER, -- time when this side first claimed the nameplate + `added` INTEGER, -- time when this side first opened the mailbox `mood` VARCHAR ); @@ -95,6 +96,7 @@ CREATE TABLE `mailbox_usage` -- "crowded": three or more sides were involved ); CREATE INDEX `mailbox_usage_idx` ON `mailbox_usage` (`app_id`, `started`); +CREATE INDEX `mailbox_usage_result_idx` ON `mailbox_usage` (`result`); CREATE TABLE `transit_usage` ( @@ -109,3 +111,4 @@ CREATE TABLE `transit_usage` -- "happy": both sides gave correct handshake ); CREATE INDEX `transit_usage_idx` ON `transit_usage` (`started`); +CREATE INDEX `transit_usage_result_idx` ON `transit_usage` (`result`);