From e65168db55a91874abecefc5abb76aaa4a68e365 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 5 Jan 2017 11:49:13 +0100 Subject: [PATCH] db model: introduce indexes for better performance --- createdb.nim | 4 ++++ editdb.nim | 16 +++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/createdb.nim b/createdb.nim index 4162c36..83e4b86 100644 --- a/createdb.nim +++ b/createdb.nim @@ -90,6 +90,10 @@ create table if not exists antibot( );""", []): echo "antibot table already exists" + +db.exec sql"create index PersonStatusIdx on person(status);" +db.exec sql"create index PostByAuthorIdx on post(thread, author);" + # -------------------- Search -------------------------------------------------- if not db.tryExec(sql""" diff --git a/editdb.nim b/editdb.nim index e12f679..7588822 100644 --- a/editdb.nim +++ b/editdb.nim @@ -4,10 +4,16 @@ import strutils, db_sqlite, ranks var db = open(connection="nimforum.db", user="postgres", password="", database="nimforum") -db.exec(sql("update person set status = ?"), $User) -db.exec(sql("update person set status = ? where ban <> ''"), $Troll) -db.exec(sql("update person set status = ? where ban like '%spam%'"), $Spammer) -db.exec(sql("update person set status = ? where ban = 'DEACTIVATED' or ban = 'EMAILCONFIRMATION'"), $EmailUnconfirmed) -db.exec(sql("update person set status = ? where admin = 'true'"), $Admin) +when false: + db.exec(sql("update person set status = ?"), $User) + db.exec(sql("update person set status = ? where ban <> ''"), $Troll) + db.exec(sql("update person set status = ? where ban like '%spam%'"), $Spammer) + db.exec(sql("update person set status = ? where ban = 'DEACTIVATED' or ban = 'EMAILCONFIRMATION'"), $EmailUnconfirmed) + db.exec(sql("update person set status = ? where admin = 'true'"), $Admin) +else: + db.exec sql"create index PersonStatusIdx on person(status);" + db.exec sql"create index PostByAuthorIdx on post(thread, author);" + db.exec sql"update person set name = 'cheatfate' where name = 'ka';" + close(db)