From d0cb5d85022f9843d4479d4cd13f283b1214e092 Mon Sep 17 00:00:00 2001 From: mahdi Date: Sat, 2 Dec 2023 14:07:53 +0100 Subject: [PATCH] db - amend SizeTable method --- db/db.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/db/db.go b/db/db.go index e0ed924..fb65da6 100644 --- a/db/db.go +++ b/db/db.go @@ -176,7 +176,7 @@ type TableSize struct { } func (db *Db) SizeTable(dbname string) []TableSize { - rs := make([]TableSize, 1) + rs := make([]TableSize, 0) db.onDbExec("information_schema", func(sqlDb *sql.DB) bool { query := "SELECT `TABLE_NAME` AS `table`, ROUND(((`DATA_LENGTH` + `INDEX_LENGTH`) / 1024 / 1024), 2) `size` FROM `TABLES` WHERE `table_schema` = ? AND (`DATA_LENGTH` + `INDEX_LENGTH`) > 0 ORDER BY (`DATA_LENGTH` + `INDEX_LENGTH`) DESC;" rows, err := sqlDb.Query(query, dbname) @@ -191,9 +191,7 @@ func (db *Db) SizeTable(dbname string) []TableSize { fmt.Printf("cannot get table size of db %s : %v", dbname, err) return false } - if len(ts.Table) > 0 { - rs = append(rs, ts) - } + rs = append(rs, ts) } return true })