Archived
1
0

remove fully

This commit is contained in:
Jeff Becker 2018-11-27 10:57:24 -05:00
parent 28e8e95207
commit a9f8bf2f8c
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05
3 changed files with 22 additions and 12 deletions

View File

@ -49,11 +49,10 @@ func (self PostEntry) Count() int64 {
type PostEntryList []PostEntry type PostEntryList []PostEntry
// stats about newsgroup postings // stats about newsgroup postings
type NewsgroupStats struct { type NewsgroupStats struct {
PPD int64 PPD int64
Name string Name string
} }
type PostingStatsEntry struct { type PostingStatsEntry struct {
@ -69,8 +68,6 @@ type NewsgroupListEntry [3]string
type NewsgroupList []NewsgroupListEntry type NewsgroupList []NewsgroupListEntry
type Database interface { type Database interface {
Close() Close()
CreateTables() CreateTables()
@ -247,6 +244,9 @@ type Database interface {
// delete an article from the database // delete an article from the database
DeleteArticle(msg_id string) error DeleteArticle(msg_id string) error
// remove an article from the database
RemoveArticle(msg_id string) error
// detele the existance of a thread from the threads table, does NOT remove replies // detele the existance of a thread from the threads table, does NOT remove replies
DeleteThread(root_msg_id string) error DeleteThread(root_msg_id string) error

View File

@ -442,10 +442,11 @@ func (mod *modEngine) Do(ev ModEvent) {
// TODP: implement // TODP: implement
} else if action == ModRemove { } else if action == ModRemove {
if ValidMessageID(target) { if ValidMessageID(target) {
err := mod.database.DeleteArticle(target) err := mod.database.RemoveArticle(target)
if err == nil { if err != nil {
err = mod.store.Remove(target) log.Println("failed to forget", target, "because:", err)
} }
err = mod.store.Remove(target)
if err == nil { if err == nil {
log.Println("removed", target) log.Println("removed", target)
} else { } else {

View File

@ -153,10 +153,11 @@ const GetYearlyPostHistory = "GetYearlyPostHistory"
const GetNewsgroupList = "GetNewsgroupList" const GetNewsgroupList = "GetNewsgroupList"
const CountUkko = "CountUkko" const CountUkko = "CountUkko"
const GetNewsgroupStats = "GetNewsgroupStats" const GetNewsgroupStats = "GetNewsgroupStats"
const RemoveArticle = "RemoveArticle"
func (self *PostgresDatabase) prepareStatements() { func (self *PostgresDatabase) prepareStatements() {
self.stmt = map[string]string{ self.stmt = map[string]string{
GetNewsgroupStats: "SELECT COUNT(message_id), newsgroup FROM articleposts WHERE time_posted > (EXTRACT(epoch FROM NOW()) - (24*3600)) GROUP BY newsgroup", GetNewsgroupStats: "SELECT COUNT(message_id), newsgroup FROM articleposts WHERE time_posted > (EXTRACT(epoch FROM NOW()) - (24*3600)) GROUP BY newsgroup",
NewsgroupBanned: "SELECT 1 FROM BannedGroups WHERE newsgroup = $1", NewsgroupBanned: "SELECT 1 FROM BannedGroups WHERE newsgroup = $1",
ArticleBanned: "SELECT 1 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 )",
@ -226,6 +227,7 @@ func (self *PostgresDatabase) prepareStatements() {
GetCitesByPostHashLike: "SELECT message_id, message_ref_id FROM Articles WHERE message_id_hash LIKE $1", GetCitesByPostHashLike: "SELECT message_id, message_ref_id FROM Articles WHERE message_id_hash LIKE $1",
GetYearlyPostHistory: "WITH times(endtime, begintime) AS ( SELECT CAST(EXTRACT(epoch from i) AS BIGINT) AS endtime, CAST(EXTRACT(epoch from i - interval '1 month') AS BIGINT) AS begintime FROM generate_series(now() - interval '10 year', now(), '1 month'::interval) i ) SELECT begintime, endtime, ( SELECT count(*) FROM ArticlePosts WHERE time_posted > begintime AND time_posted < endtime) FROM times", GetYearlyPostHistory: "WITH times(endtime, begintime) AS ( SELECT CAST(EXTRACT(epoch from i) AS BIGINT) AS endtime, CAST(EXTRACT(epoch from i - interval '1 month') AS BIGINT) AS begintime FROM generate_series(now() - interval '10 year', now(), '1 month'::interval) i ) SELECT begintime, endtime, ( SELECT count(*) FROM ArticlePosts WHERE time_posted > begintime AND time_posted < endtime) FROM times",
CountUkko: "SELECT COUNT(message_id) FROM ArticlePosts WHERE newsgroup != 'ctl' AND ref_id = '' OR ref_id = message_id", CountUkko: "SELECT COUNT(message_id) FROM ArticlePosts WHERE newsgroup != 'ctl' AND ref_id = '' OR ref_id = message_id",
RemoveArticle: "DELETE FROM Articles WHERE message_id = $1",
} }
} }
@ -1245,6 +1247,14 @@ func (self *PostgresDatabase) DeleteArticle(msgid string) (err error) {
*/ */
_, err = self.conn.Exec(self.stmt[DeleteArticleV8], msgid) _, err = self.conn.Exec(self.stmt[DeleteArticleV8], msgid)
return return
}
func (self *PostgresDatabase) RemoveArticle(msgid string) (err error) {
_, err = self.conn.Exec(self.stmt[DeleteArticleV8], msgid)
if err == nil {
_, err = self.conn.Exec(self.stmt[RemoveArticle], msgid)
}
return
} }
func (self *PostgresDatabase) GetThreadReplyPostModels(prefix, rootpost string, start, limit int) (repls []PostModel) { func (self *PostgresDatabase) GetThreadReplyPostModels(prefix, rootpost string, start, limit int) (repls []PostModel) {
@ -2053,7 +2063,7 @@ func (self *PostgresDatabase) GetUkkoPageCount(perpage int) (count int64, err er
return return
} }
func (self *PostgresDatabase) GetNewsgroupStats() (stats []NewsgroupStats, err error) { func (self *PostgresDatabase) GetNewsgroupStats() (stats []NewsgroupStats, err error) {
var rows *sql.Rows var rows *sql.Rows
rows, err = self.conn.Query(self.stmt[GetNewsgroupStats]) rows, err = self.conn.Query(self.stmt[GetNewsgroupStats])
if err == nil { if err == nil {
@ -2067,7 +2077,6 @@ func (self *PostgresDatabase) GetNewsgroupStats() (stats []NewsgroupStats, err e
return return
} }
func (self *PostgresDatabase) FindHeaders(group, headername string, lo, hi int64) (hdr ArticleHeaders, err error) { func (self *PostgresDatabase) FindHeaders(group, headername string, lo, hi int64) (hdr ArticleHeaders, err error) {
hdr = make(ArticleHeaders) hdr = make(ArticleHeaders)
q := "SELECT header_value FROM nntpheaders WHERE header_name = $1 AND header_article_message_id IN ( SELECT message_id FROM articleposts WHERE newsgroup = $2 )" q := "SELECT header_value FROM nntpheaders WHERE header_name = $1 AND header_article_message_id IN ( SELECT message_id FROM articleposts WHERE newsgroup = $2 )"