~emersion/drmdb

f5007b791002d8c1bf56535c2825c824fbe6aa9d — Simon Ser 4 months ago 8f5adfe
Print some stats on the index page
2 files changed, 27 insertions(+), 2 deletions(-)

M public/index.html
M server.go
M public/index.html => public/index.html +3 -0
@@ 4,6 4,9 @@
<p>This is a database of Direct Rendering Manager dumps. This database is
used to keep track of GPUs and DRM driver features support.</p>

<p>The database currently contains {{ .NumSnapshots }} snapshots with
{{ .NumDevices }} devices and {{ .NumDrivers }} drivers.</p>

<h2>Browse</h2>
<ul>
    <li><a href="/drivers">Drivers</a></li>

M server.go => server.go +24 -2
@@ 75,9 75,31 @@ func New() *echo.Echo {
	}

	e.GET("/", func(c echo.Context) error {
		return c.Render(http.StatusOK, "index.html", struct {
		data := struct {
			Host string
		}{c.Request().Host})
			NumSnapshots int
			NumDevices   int
			NumDrivers   int
		}{}

		data.Host = c.Request().Host

		devices := make(map[string]struct{})
		drivers := make(map[string]struct{})
		err := db.Walk(func(k string, n *drmtree.Node) error {
			data.NumSnapshots++
			devices[n.Device.BusID()] = struct{}{}
			drivers[n.Driver.Name] = struct{}{}
			return nil
		})
		if err != nil {
			return err
		}

		data.NumDevices = len(devices)
		data.NumDrivers = len(drivers)

		return c.Render(http.StatusOK, "index.html", &data)
	})

	e.POST("/submit", func(c echo.Context) error {