db model: introduce indexes for better performance

This commit is contained in:
Andreas Rumpf 2017-01-05 11:49:13 +01:00
commit e65168db55
2 changed files with 15 additions and 5 deletions

View file

@ -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"""

View file

@ -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)