optimizations
This commit is contained in:
parent
412c2ad4ca
commit
52634b7edd
@ -865,7 +865,10 @@ func (self *nntpConnection) handleLine(daemon *NNTPDaemon, code int, line string
|
|||||||
if daemon.database.HasNewsgroup(group) {
|
if daemon.database.HasNewsgroup(group) {
|
||||||
// we has newsgroup
|
// we has newsgroup
|
||||||
var hi, lo int64
|
var hi, lo int64
|
||||||
count, err := daemon.database.CountAllArticlesInGroup(group)
|
// THIS is heavy as shit
|
||||||
|
//count, err := daemon.database.CountAllArticlesInGroup(group)
|
||||||
|
var err error
|
||||||
|
count := 0
|
||||||
if err == nil {
|
if err == nil {
|
||||||
hi, lo, err = daemon.database.GetLastAndFirstForGroup(group)
|
hi, lo, err = daemon.database.GetLastAndFirstForGroup(group)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
@ -899,13 +902,13 @@ func (self *nntpConnection) handleLine(daemon *NNTPDaemon, code int, line string
|
|||||||
// for each group
|
// for each group
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
// get low/high water mark
|
// get low/high water mark
|
||||||
lo, hi, err := daemon.database.GetLastAndFirstForGroup(group)
|
// XXX: heavy as shit
|
||||||
if err == nil {
|
//lo, hi, err := daemon.database.GetLastAndFirstForGroup(group)
|
||||||
// XXX: we ignore errors here :\
|
//if err == nil {
|
||||||
_, _ = io.WriteString(dw, fmt.Sprintf("%s %d %d y\n", group, lo, hi))
|
_, _ = io.WriteString(dw, fmt.Sprintf("%s 0 0 y\n", group))
|
||||||
} else {
|
//} else {
|
||||||
log.Println(self.name, "could not get low/high water mark for", group, err)
|
// log.Println(self.name, "could not get low/high water mark for", group, err)
|
||||||
}
|
//}
|
||||||
}
|
}
|
||||||
// flush dotwriter
|
// flush dotwriter
|
||||||
dw.Close()
|
dw.Close()
|
||||||
|
@ -149,8 +149,8 @@ const GetYearlyPostHistory = "GetYearlyPostHistory"
|
|||||||
|
|
||||||
func (self *PostgresDatabase) prepareStatements() {
|
func (self *PostgresDatabase) prepareStatements() {
|
||||||
self.stmt = map[string]string{
|
self.stmt = map[string]string{
|
||||||
NewsgroupBanned: "SELECT COUNT(newsgroup) FROM BannedGroups WHERE newsgroup = $1",
|
NewsgroupBanned: "SELECT 1 FROM BannedGroups WHERE newsgroup = $1",
|
||||||
ArticleBanned: "SELECT COUNT(message_id) FROM BannedArticles WHERE message_id = $1",
|
ArticleBanned: "SELECT 1 FROM BannedArticles WHERE message_id = $1",
|
||||||
GetAllNewsgroups: "SELECT name FROM Newsgroups WHERE name NOT IN ( SELECT newsgroup FROM BannedGroups )",
|
GetAllNewsgroups: "SELECT name FROM Newsgroups WHERE name NOT IN ( SELECT newsgroup FROM BannedGroups )",
|
||||||
GetPostsInGroup: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE newsgroup = $1 ORDER BY time_posted",
|
GetPostsInGroup: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE newsgroup = $1 ORDER BY time_posted",
|
||||||
GetPostModel: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE message_id = $1 LIMIT 1",
|
GetPostModel: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE message_id = $1 LIMIT 1",
|
||||||
@ -171,9 +171,9 @@ func (self *PostgresDatabase) prepareStatements() {
|
|||||||
GetGroupThreads: "SELECT message_id FROM ArticlePosts WHERE newsgroup = $1 AND ref_id = '' ",
|
GetGroupThreads: "SELECT message_id FROM ArticlePosts WHERE newsgroup = $1 AND ref_id = '' ",
|
||||||
GetLastBumpedThreadsPaginated_1: "SELECT root_message_id, newsgroup FROM ArticleThreads WHERE newsgroup = $1 ORDER BY last_bump DESC LIMIT $2",
|
GetLastBumpedThreadsPaginated_1: "SELECT root_message_id, newsgroup FROM ArticleThreads WHERE newsgroup = $1 ORDER BY last_bump DESC LIMIT $2",
|
||||||
GetLastBumpedThreadsPaginated_2: "SELECT root_message_id, newsgroup FROM ArticleThreads WHERE newsgroup != 'ctl' ORDER BY last_bump DESC LIMIT $1",
|
GetLastBumpedThreadsPaginated_2: "SELECT root_message_id, newsgroup FROM ArticleThreads WHERE newsgroup != 'ctl' ORDER BY last_bump DESC LIMIT $1",
|
||||||
HasNewsgroup: "SELECT COUNT(name) FROM Newsgroups WHERE name = $1",
|
HasNewsgroup: "SELECT 1 FROM Newsgroups WHERE name = $1",
|
||||||
HasArticle: "SELECT COUNT(message_id) FROM Articles WHERE message_id = $1",
|
HasArticle: "SELECT 1 FROM Articles WHERE message_id = $1",
|
||||||
HasArticleLocal: "SELECT COUNT(message_id) FROM ArticlePosts WHERE message_id = $1",
|
HasArticleLocal: "SELECT 1 FROM ArticlePosts WHERE message_id = $1",
|
||||||
GetPostAttachments: "SELECT filepath FROM ArticleAttachments WHERE message_id = $1",
|
GetPostAttachments: "SELECT filepath FROM ArticleAttachments WHERE message_id = $1",
|
||||||
GetPostAttachmentModels: "SELECT filepath, filename FROM ArticleAttachments WHERE message_id = $1",
|
GetPostAttachmentModels: "SELECT filepath, filename FROM ArticleAttachments WHERE message_id = $1",
|
||||||
RegisterArticle_1: "INSERT INTO Articles (message_id, message_id_hash, message_newsgroup, time_obtained, message_ref_id) VALUES($1, $2, $3, $4, $5)",
|
RegisterArticle_1: "INSERT INTO Articles (message_id, message_id_hash, message_newsgroup, time_obtained, message_ref_id) VALUES($1, $2, $3, $4, $5)",
|
||||||
@ -189,7 +189,7 @@ func (self *PostgresDatabase) prepareStatements() {
|
|||||||
GetAllArticlesInGroup: "SELECT message_id FROM ArticlePosts WHERE newsgroup = $1",
|
GetAllArticlesInGroup: "SELECT message_id FROM ArticlePosts WHERE newsgroup = $1",
|
||||||
GetAllArticles: "SELECT message_id, newsgroup FROM ArticlePosts",
|
GetAllArticles: "SELECT message_id, newsgroup FROM ArticlePosts",
|
||||||
GetMessageIDByHash: "SELECT message_id, message_newsgroup FROM Articles WHERE message_id_hash = $1 LIMIT 1",
|
GetMessageIDByHash: "SELECT message_id, message_newsgroup FROM Articles WHERE message_id_hash = $1 LIMIT 1",
|
||||||
CheckEncIPBanned: "SELECT COUNT(*) FROM EncIPBans WHERE encaddr = $1",
|
CheckEncIPBanned: "SELECT 1 FROM EncIPBans WHERE encaddr = $1",
|
||||||
GetFirstAndLastForGroup: "WITH x(min_no, max_no) AS ( SELECT MIN(message_no) AS min_no, MAX(message_no) AS max_no FROM ArticleNumbers WHERE newsgroup = $1) SELECT CASE WHEN min_no IS NULL THEN 0 ELSE min_no END AS min_no FROM x UNION SELECT CASE WHEN max_no IS NULL THEN 1 ELSE max_no END AS max_no FROM x",
|
GetFirstAndLastForGroup: "WITH x(min_no, max_no) AS ( SELECT MIN(message_no) AS min_no, MAX(message_no) AS max_no FROM ArticleNumbers WHERE newsgroup = $1) SELECT CASE WHEN min_no IS NULL THEN 0 ELSE min_no END AS min_no FROM x UNION SELECT CASE WHEN max_no IS NULL THEN 1 ELSE max_no END AS max_no FROM x",
|
||||||
GetMessageIDForNNTPID: "SELECT message_id FROM ArticleNumbers WHERE newsgroup = $1 AND message_no = $2 LIMIT 1",
|
GetMessageIDForNNTPID: "SELECT message_id FROM ArticleNumbers WHERE newsgroup = $1 AND message_no = $2 LIMIT 1",
|
||||||
GetNNTPIDForMessageID: "SELECT message_no FROM ArticleNumbers WHERE newsgroup = $1 AND message_id = $2 LIMIT 1",
|
GetNNTPIDForMessageID: "SELECT message_no FROM ArticleNumbers WHERE newsgroup = $1 AND message_id = $2 LIMIT 1",
|
||||||
@ -199,7 +199,7 @@ func (self *PostgresDatabase) prepareStatements() {
|
|||||||
GetLastPostedPostModels: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE newsgroup != 'ctl' ORDER BY time_posted DESC LIMIT $1",
|
GetLastPostedPostModels: "SELECT newsgroup, message_id, ref_id, name, subject, path, time_posted, message, addr FROM ArticlePosts WHERE newsgroup != 'ctl' ORDER BY time_posted DESC LIMIT $1",
|
||||||
GetMonthlyPostHistory: "SELECT time_posted FROM ArticlePosts WHERE time_posted > 0 ORDER BY time_posted ASC LIMIT 1",
|
GetMonthlyPostHistory: "SELECT time_posted FROM ArticlePosts WHERE time_posted > 0 ORDER BY time_posted ASC LIMIT 1",
|
||||||
CheckNNTPLogin: "SELECT login_hash, login_salt FROM NNTPUsers WHERE username = $1",
|
CheckNNTPLogin: "SELECT login_hash, login_salt FROM NNTPUsers WHERE username = $1",
|
||||||
CheckNNTPUserExists: "SELECT COUNT(username) FROM NNTPUsers WHERE username = $1",
|
CheckNNTPUserExists: "SELECT 1 FROM NNTPUsers WHERE username = $1",
|
||||||
GetHeadersForMessage: "SELECT header_name, header_value FROM NNTPHeaders WHERE header_article_message_id = $1",
|
GetHeadersForMessage: "SELECT header_name, header_value FROM NNTPHeaders WHERE header_article_message_id = $1",
|
||||||
CountAllArticlesInGroup: "SELECT COUNT(message_id) FROM ArticlePosts WHERE newsgroup = $1",
|
CountAllArticlesInGroup: "SELECT COUNT(message_id) FROM ArticlePosts WHERE newsgroup = $1",
|
||||||
GetMessageIDByCIDR: "SELECT message_id FROM ArticlePosts WHERE addr IN ( SELECT encaddr FROM EncryptedAddrs WHERE addr_cidr <<= cidr($1) )",
|
GetMessageIDByCIDR: "SELECT message_id FROM ArticlePosts WHERE addr IN ( SELECT encaddr FROM EncryptedAddrs WHERE addr_cidr <<= cidr($1) )",
|
||||||
|
Reference in New Issue
Block a user