Show database file size on info page
This commit is contained in:
parent
a03baca498
commit
f98df478bb
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -286,5 +287,11 @@ func (m *BookmarkManager) Stats() (entity.DBStats, error) {
|
|||||||
if err != nil && err != bolthold.ErrNotFound {
|
if err != nil && err != bolthold.ErrNotFound {
|
||||||
return stats, fmt.Errorf("could not load stats: %s", err)
|
return stats, fmt.Errorf("could not load stats: %s", err)
|
||||||
}
|
}
|
||||||
|
// get the DB size
|
||||||
|
fi, err := os.Stat(m.db.file)
|
||||||
|
if err != nil {
|
||||||
|
return stats, fmt.Errorf("could not load db file size: %s", err)
|
||||||
|
}
|
||||||
|
stats.FileSize = int(fi.Size())
|
||||||
return stats, nil
|
return stats, nil
|
||||||
}
|
}
|
||||||
|
2
db/db.go
2
db/db.go
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
type DB struct {
|
type DB struct {
|
||||||
store *bolthold.Store
|
store *bolthold.Store
|
||||||
|
file string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (db *DB) Open(path string) error {
|
func (db *DB) Open(path string) error {
|
||||||
@ -21,6 +22,7 @@ func (db *DB) Open(path string) error {
|
|||||||
return fmt.Errorf("cannot open '%s' - %s", path, err)
|
return fmt.Errorf("cannot open '%s' - %s", path, err)
|
||||||
}
|
}
|
||||||
db.store = store
|
db.store = store
|
||||||
|
db.file = path
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
|
|
||||||
type DBStats struct {
|
type DBStats struct {
|
||||||
History map[time.Time]BookmarkInfo
|
History map[time.Time]BookmarkInfo
|
||||||
|
FileSize int
|
||||||
Searches int
|
Searches int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,6 @@ func MemInfo() string {
|
|||||||
stats := runtime.MemStats{}
|
stats := runtime.MemStats{}
|
||||||
runtime.ReadMemStats(&stats)
|
runtime.ReadMemStats(&stats)
|
||||||
|
|
||||||
return fmt.Sprintf("%.3fMb", float64(stats.Alloc)/1024.0/1024.0)
|
return fmt.Sprintf("%.1fMb", float64(stats.Alloc)/1024.0/1024.0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ import (
|
|||||||
"golang.org/x/mod/semver"
|
"golang.org/x/mod/semver"
|
||||||
)
|
)
|
||||||
|
|
||||||
const Tag = "v0.0.32"
|
const Tag = "v0.0.33"
|
||||||
|
|
||||||
type Info struct {
|
type Info struct {
|
||||||
Local struct {
|
Local struct {
|
||||||
|
@ -1,12 +1,16 @@
|
|||||||
<div class="grid-x grid-padding-x">
|
<div class="grid-x grid-padding-x">
|
||||||
<div class="large-12 cell">
|
<div class="large-6 medium-12 cell">
|
||||||
|
|
||||||
<h5>System information</h5>
|
<h5>System information</h5>
|
||||||
<table>
|
<table>
|
||||||
<tr><th>Memory in use</th><td>{{ meminfo }}</td></tr>
|
<tr><th>Memory in use</th><td>{{ meminfo }}</td></tr>
|
||||||
<tr><th>Bookmarks</th><td>{{ .stats.MostRecentBookmarkInfo.Bookmarks }}</td></tr>
|
<tr><th>Bookmarks</th><td>{{ .stats.MostRecentBookmarkInfo.Bookmarks }}</td></tr>
|
||||||
<tr><th>Words Indexed</th><td>{{ .stats.MostRecentBookmarkInfo.IndexedWords }}</td></tr>
|
<tr><th>Words Indexed</th><td>{{ .stats.MostRecentBookmarkInfo.IndexedWords }}</td></tr>
|
||||||
|
<tr><th>Database disk size</th><td>{{ niceSizeMB .stats.FileSize }}Mb</td></tr>
|
||||||
|
|
||||||
</table>
|
</table>
|
||||||
|
</div>
|
||||||
|
<div class="large-6 medium-12 cell">
|
||||||
|
|
||||||
<h5>Release info</h5>
|
<h5>Release info</h5>
|
||||||
{{ if not version.Remote.Valid }}
|
{{ if not version.Remote.Valid }}
|
||||||
|
13
web/web.go
13
web/web.go
@ -79,12 +79,13 @@ func Create(bmm *db.BookmarkManager, cmm *db.ConfigManager) *Server {
|
|||||||
// templ := template.Must(template.New("").Funcs(template.FuncMap{"dict": dictHelper}).ParseFS(templateFiles, "templates/*.html"))
|
// templ := template.Must(template.New("").Funcs(template.FuncMap{"dict": dictHelper}).ParseFS(templateFiles, "templates/*.html"))
|
||||||
templ := template.Must(template.New("").Funcs(
|
templ := template.Must(template.New("").Funcs(
|
||||||
template.FuncMap{
|
template.FuncMap{
|
||||||
"nicetime": niceTime,
|
"nicetime": niceTime,
|
||||||
"niceURL": niceURL,
|
"niceURL": niceURL,
|
||||||
"join": strings.Join,
|
"niceSizeMB": func(s int) string { return fmt.Sprintf("%.1f", float32(s)/1024/1024) },
|
||||||
"version": func() *version.Info { return &version.VersionInfo },
|
"join": strings.Join,
|
||||||
"meminfo": meta.MemInfo,
|
"version": func() *version.Info { return &version.VersionInfo },
|
||||||
"markdown": func(s string) template.HTML { return template.HTML(string(markdown.ToHTML([]byte(s), nil, nil))) },
|
"meminfo": meta.MemInfo,
|
||||||
|
"markdown": func(s string) template.HTML { return template.HTML(string(markdown.ToHTML([]byte(s), nil, nil))) },
|
||||||
}).ParseFS(templateFiles, "templates/*.html"))
|
}).ParseFS(templateFiles, "templates/*.html"))
|
||||||
|
|
||||||
config, err := cmm.LoadConfig()
|
config, err := cmm.LoadConfig()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user