Skip to content

Commit

Permalink
Merge pull request #667 from stakwork/aa/feature/db-message-index
Browse files Browse the repository at this point in the history
Add index on messageDbo and chatDbo tables
  • Loading branch information
ariel10aguero authored Nov 2, 2023
2 parents 809e3a0 + ecb55fb commit c37e74b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ SET price_per_message = :price_per_message,
pin_message = :pin_message
WHERE id = ?;

CREATE INDEX idx_chat_id ON chatDbo(id);
CREATE INDEX idx_chat_type ON chatDbo(type);
CREATE INDEX idx_chat_latest_message_id ON chatDbo(latest_message_id);
CREATE INDEX idx_chat_name ON chatDbo(name);

CREATE TABLE contactDbo(
id INTEGER AS ContactId NOT NULL PRIMARY KEY,
route_hint TEXT AS LightningRouteHint,
Expand Down Expand Up @@ -966,6 +971,14 @@ UPDATE messageMediaDbo
SET local_file = NULL
WHERE chat_id = ? AND id IN ?;

CREATE INDEX idx_message_chat_type_status ON messageDbo(chat_id, type, status);
CREATE INDEX idx_message_chat_type_reply_thread ON messageDbo(chat_id, type, reply_uuid, thread_uuid);
CREATE INDEX idx_message_uuid ON messageDbo(uuid);
CREATE INDEX idx_message_chat_date ON messageDbo(chat_id, date DESC);
CREATE INDEX idx_message_sender_chat_type ON messageDbo(sender, chat_id, type);
CREATE INDEX idx_message_id ON messageDbo(id);
CREATE INDEX idx_message_muid_original_muid ON messageDbo(muid, original_muid);

CREATE TABLE subscriptionDbo(
id INTEGER AS SubscriptionId NOT NULL PRIMARY KEY,
cron TEXT AS Cron NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

CREATE INDEX idx_message_chat_type_status ON messageDbo(chat_id, type, status);
CREATE INDEX idx_message_chat_type_reply_thread ON messageDbo(chat_id, type, reply_uuid, thread_uuid);
CREATE INDEX idx_message_uuid ON messageDbo(uuid);
CREATE INDEX idx_message_chat_date ON messageDbo(chat_id, date DESC);
CREATE INDEX idx_message_sender_chat_type ON messageDbo(sender, chat_id, type);
CREATE INDEX idx_message_id ON messageDbo(id);
CREATE INDEX idx_message_muid_original_muid ON messageDbo(muid, original_muid);

CREATE INDEX idx_chat_id ON chatDbo(id);
CREATE INDEX idx_chat_type ON chatDbo(type);
CREATE INDEX idx_chat_latest_message_id ON chatDbo(latest_message_id);
CREATE INDEX idx_chat_name ON chatDbo(name);

0 comments on commit c37e74b

Please sign in to comment.