vole
Site
Clone
Read only, no credentials:
https://rodent.software/vole.git
Write over SSH with a registered key:
git clone ssh://git@rodent.software/vole.git
Self-hosted forge that lives in your Git repo.
Remove page-view tracking
0a12642f6c01236d1fbd4ee06aaa2bd2283c6bf0 · Keenan Nemetz · 3d ago · parent 8f6548a6
Remove page-view tracking Counting a page wrote a row to instance.db on every successful HTML GET, so reading the instance contended with CI and the merge worker for the one write lock. The counters answered one status page and were not part of what a restore has to keep, so the feature is gone rather than moved. The status overview loses its page-view card and table; the rest of the Admin page is unchanged. An instance that recorded views keeps the old page_views table in instance.db, which nothing reads. Refs #398
server/web/auth.go +2−42
| @@ -102,13 +102,9 @@ func (w *Web) principal(r *http.Request) *principal { | |||
| 102 | 102 | type statusWriter struct { | |
| 103 | 103 | http.ResponseWriter | |
| 104 | 104 | wroteHeader bool | |
| 105 | status int | ||
| 106 | 105 | } | |
| 107 | 106 | ||
| 108 | 107 | func (s *statusWriter) WriteHeader(code int) { | |
| 109 | if !s.wroteHeader { | ||
| 110 | s.status = code | ||
| 111 | } | ||
| 112 | 108 | s.wroteHeader = true | |
| 113 | 109 | s.ResponseWriter.WriteHeader(code) | |
| 114 | 110 | } | |
| @@ -116,7 +112,6 @@ func (s *statusWriter) WriteHeader(code int) { | |||
| 116 | 112 | func (s *statusWriter) Write(b []byte) (int, error) { | |
| 117 | 113 | if !s.wroteHeader { | |
| 118 | 114 | s.wroteHeader = true | |
| 119 | s.status = http.StatusOK | ||
| 120 | 115 | } | |
| 121 | 116 | return s.ResponseWriter.Write(b) | |
| 122 | 117 | } | |
| @@ -161,8 +156,8 @@ func (w *Web) Middleware(next http.Handler) http.Handler { | |||
| 161 | 156 | } | |
| 162 | 157 | } | |
| 163 | 158 | sw := &statusWriter{ResponseWriter: rw} | |
| 164 | // gzip is per request: the status recorder under it is what records the | ||
| 165 | // status and the page-view metric, and the compressor only shapes bytes. | ||
| 159 | // gzip is per request: the status recorder under it is what knows whether a | ||
| 160 | // reply has started, and the compressor only shapes bytes. | ||
| 166 | 161 | gw := compress.New(sw, r) | |
| 167 | 162 | defer func() { | |
| 168 | 163 | v := recover() | |
| @@ -181,44 +176,9 @@ func (w *Web) Middleware(next http.Handler) http.Handler { | |||
| 181 | 176 | }() | |
| 182 | 177 | next.ServeHTTP(gw, r) | |
| 183 | 178 | gw.Close() | |
| 184 | w.recordPageView(r, sw) | ||
| 185 | 179 | }) | |
| 186 | 180 | } | |
| 187 | 181 | ||
| 188 | // recordPageView counts a successfully rendered HTML page. Static files, Git | ||
| 189 | // traffic, redirects, HTMX fragments and the admin surface itself are excluded, so | ||
| 190 | // the metric follows reading rather than polling or asset loads. It is | ||
| 191 | // best-effort: analytics must never turn a page into an error. | ||
| 192 | func (w *Web) recordPageView(r *http.Request, sw *statusWriter) { | ||
| 193 | if w.PageViews == nil || r.Method != http.MethodGet || sw.status != http.StatusOK { | ||
| 194 | return | ||
| 195 | } | ||
| 196 | if r.Header.Get("HX-Request") == "true" || adminPath(r.URL.Path) { | ||
| 197 | return | ||
| 198 | } | ||
| 199 | if !strings.HasPrefix(sw.Header().Get("Content-Type"), "text/html") { | ||
| 200 | return | ||
| 201 | } | ||
| 202 | // A module discovery probe is answered with HTML but is not a page. | ||
| 203 | if r.URL.Query().Get("go-get") != "" { | ||
| 204 | return | ||
| 205 | } | ||
| 206 | account := "" | ||
| 207 | if pr := w.principal(r); pr != nil { | ||
| 208 | account = pr.account.Name | ||
| 209 | } | ||
| 210 | if err := w.PageViews.Record(account, time.Now().UTC()); err != nil && w.Logger != nil { | ||
| 211 | w.Logger("page view: %v", err) | ||
| 212 | } | ||
| 213 | } | ||
| 214 | |||
| 215 | // adminPath reports whether a path belongs to the instance-admin surface. Those | ||
| 216 | // pages are read by the same few people watching the instance, so counting them | ||
| 217 | // would measure administration rather than readership. | ||
| 218 | func adminPath(path string) bool { | ||
| 219 | return path == "/-/admin" || path == "/-/status" || path == "/-/users" || strings.HasPrefix(path, "/-/users/") | ||
| 220 | } | ||
| 221 | |||
| 222 | 182 | // sessionFromCookie returns the first valid session cookie and the name it came | |
| 223 | 183 | // from. The dev cookie is only considered when dev login is enabled, so a stray | |
| 224 | 184 | // cookie on a normal instance is never a credential. | |