1
0
mirror of https://github.com/axllent/mailpit.git synced 2025-08-15 20:13:16 +02:00

Merge branch 'feature/rqlite-float64' into develop

This commit is contained in:
Ralph Slooten
2025-06-14 12:24:06 +12:00
7 changed files with 39 additions and 35 deletions

View File

@@ -100,6 +100,9 @@ func TestPOP3(t *testing.T) {
return
}
// allow for background delete when using rqlite driver
time.Sleep(time.Millisecond * 200)
c, err = connectAuth()
if err != nil {
t.Errorf(err.Error())

View File

@@ -57,7 +57,7 @@ func pruneMessages() {
ids := []string{}
var prunedSize uint64
var size uint64
var size float64 // use float64 for rqlite compatibility
// prune using `--max` if set
if config.MaxMessages > 0 {
@@ -81,7 +81,7 @@ func pruneMessages() {
return
}
ids = append(ids, id)
prunedSize = prunedSize + size
prunedSize = prunedSize + uint64(size)
}); err != nil {
logger.Log().Errorf("[db] %s", err.Error())
@@ -110,7 +110,7 @@ func pruneMessages() {
if !tools.InArray(id, ids) {
ids = append(ids, id)
prunedSize = prunedSize + size
prunedSize = prunedSize + uint64(size)
}
}); err != nil {

View File

@@ -211,51 +211,50 @@ func StatsGet() MailboxStats {
// CountTotal returns the number of emails in the database
func CountTotal() uint64 {
var total uint64
var total float64 // use float64 for rqlite compatibility
_ = sqlf.From(tenant("mailbox")).
Select("COUNT(*)").To(&total).
QueryRowAndClose(context.TODO(), db)
return total
return uint64(total)
}
// CountUnread returns the number of emails in the database that are unread.
func CountUnread() uint64 {
var total uint64
var total float64 // use float64 for rqlite compatibility
_ = sqlf.From(tenant("mailbox")).
Select("COUNT(*)").To(&total).
Where("Read = ?", 0).
QueryRowAndClose(context.TODO(), db)
return total
return uint64(total)
}
// CountRead returns the number of emails in the database that are read.
func CountRead() uint64 {
var total uint64
var total float64 // use float64 for rqlite compatibility
_ = sqlf.From(tenant("mailbox")).
Select("COUNT(*)").To(&total).
Where("Read = ?", 1).
QueryRowAndClose(context.TODO(), db)
return total
return uint64(total)
}
// DbSize returns the size of the SQLite database.
func DbSize() uint64 {
var total sql.NullInt64
var total sql.NullFloat64 // use float64 for rqlite compatibility
err := db.QueryRow("SELECT page_count * page_size AS size FROM pragma_page_count(), pragma_page_size()").Scan(&total)
if err != nil {
logger.Log().Errorf("[db] %s", err.Error())
return uint64(total.Int64)
}
return uint64(total.Int64)
return uint64(total.Float64)
}
// MessageIDExists checks whether a Message-ID exists in the DB

View File

@@ -201,12 +201,12 @@ func List(start int, beforeTS int64, limit int) ([]MessageSummary, error) {
}
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var created uint64
var created float64 // use float64 for rqlite compatibility
var id string
var messageID string
var subject string
var metadata string
var size uint64
var size float64 // use float64 for rqlite compatibility
var attachments int
var read int
var snippet string
@@ -226,7 +226,7 @@ func List(start int, beforeTS int64, limit int) ([]MessageSummary, error) {
em.ID = id
em.MessageID = messageID
em.Subject = subject
em.Size = size
em.Size = uint64(size)
em.Attachments = attachments
em.Read = read == 1
em.Snippet = snippet
@@ -294,7 +294,7 @@ func GetMessage(id string) (*Message, error) {
Where(`ID = ?`, id)
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var created uint64
var created float64 // use float64 for rqlite compatibility
if err := row.Scan(&created); err != nil {
logger.Log().Errorf("[db] %s", err.Error())
@@ -621,12 +621,14 @@ func DeleteMessages(ids []string) error {
for rows.Next() {
var id string
var size uint64
var size float64 // use float64 for rqlite compatibility
if err := rows.Scan(&id, &size); err != nil {
return err
}
toDelete = append(toDelete, id)
totalSize = totalSize + size
totalSize = totalSize + uint64(size)
}
if err = rows.Err(); err != nil {

View File

@@ -39,12 +39,12 @@ func Search(search, timezone string, start int, beforeTS int64, limit int) ([]Me
var err error
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var created uint64
var created float64 // use float64 for rqlite compatibility
var id string
var messageID string
var subject string
var metadata string
var size uint64
var size float64 // use float64 for rqlite compatibility
var attachments int
var snippet string
var read int
@@ -65,7 +65,7 @@ func Search(search, timezone string, start int, beforeTS int64, limit int) ([]Me
em.ID = id
em.MessageID = messageID
em.Subject = subject
em.Size = size
em.Size = uint64(size)
em.Attachments = attachments
em.Read = read == 1
em.Snippet = snippet
@@ -111,7 +111,7 @@ func SearchUnreadCount(search, timezone string, beforeTS int64) (int64, error) {
q = q.Where(`Created < ?`, beforeTS)
}
var unread int64
var unread float64 // use float64 for rqlite compatibility
q = q.Where("Read = 0").Select(`COUNT(*)`)
@@ -128,9 +128,9 @@ func SearchUnreadCount(search, timezone string, beforeTS int64) (int64, error) {
elapsed := time.Since(tsStart)
logger.Log().Debugf("[db] counted %d unread for \"%s\" in %s", unread, search, elapsed)
logger.Log().Debugf("[db] counted %d unread for \"%s\" in %s", int64(unread), search, elapsed)
return unread, err
return int64(unread), err
}
// DeleteSearch will delete all messages for search terms.
@@ -144,12 +144,12 @@ func DeleteSearch(search, timezone string) error {
deleteSize := uint64(0)
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var created uint64
var created float64 // use float64 for rqlite compatibility
var id string
var messageID string
var subject string
var metadata string
var size uint64
var size float64 // use float64 for rqlite compatibility
var attachments int
var read int
var snippet string
@@ -161,7 +161,7 @@ func DeleteSearch(search, timezone string) error {
}
ids = append(ids, id)
deleteSize = deleteSize + size
deleteSize = deleteSize + uint64(size)
}); err != nil {
return err
}
@@ -264,12 +264,12 @@ func SetSearchReadStatus(search, timezone string, read bool) error {
ids := []string{}
if err := q.QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
var created uint64
var created float64 // use float64 for rqlite compatibility
var id string
var messageID string
var subject string
var metadata string
var size uint64
var size float64 // use float64 for rqlite compatibility
var attachments int
var read int
var snippet string

View File

@@ -36,7 +36,7 @@ func SettingPut(k, v string) error {
// The total deleted message size as an int64 value
func getDeletedSize() uint64 {
var result sql.NullInt64
var result sql.NullFloat64 // use float64 for rqlite compatibility
err := sqlf.From(tenant("settings")).
Select("Value").To(&result).
Where("Key = ?", "DeletedSize").
@@ -47,12 +47,12 @@ func getDeletedSize() uint64 {
return 0
}
return uint64(result.Int64)
return uint64(result.Float64)
}
// The total raw non-compressed messages size in bytes of all messages in the database
func totalMessagesSize() uint64 {
var result sql.NullInt64
var result sql.NullFloat64
err := sqlf.From(tenant("mailbox")).
Select("SUM(Size)").To(&result).
QueryAndClose(context.TODO(), db, func(row *sql.Rows) {})
@@ -61,7 +61,7 @@ func totalMessagesSize() uint64 {
return 0
}
return uint64(result.Int64)
return uint64(result.Float64)
}
// AddDeletedSize will add the value to the DeletedSize setting

View File

@@ -171,7 +171,7 @@ func GetAllTags() []string {
func GetAllTagsCount() map[string]int64 {
var tags = make(map[string]int64)
var name string
var total int64
var total float64 // use float64 for rqlite compatibility
if err := sqlf.
Select(`Name`).To(&name).
@@ -181,7 +181,7 @@ func GetAllTagsCount() map[string]int64 {
GroupBy(tenant("message_tags.TagID")).
OrderBy("Name").
QueryAndClose(context.TODO(), db, func(row *sql.Rows) {
tags[name] = total
tags[name] = int64(total)
}); err != nil {
logger.Log().Errorf("[db] %s", err.Error())
}