refactor: simplify PWA handlers and fix review findings

Address code review findings from reuse, quality, and efficiency agents:

- Cache manifest JSON and service worker JS at init (was rebuilt per
  request with allocations and JSON encoding on every hit)
- Add ImagePathsByUser store method for targeted image cleanup (was
  loading 100k full fave objects just to read image_path)
- Add missing aria-label on privacy toggle in fave_list.html (inline
  copy had drifted from the partial — accessibility bug)
- Fix comment/function name mismatch in pwa.go
- Remove redundant user nil-check in handleShare (requireLogin guards)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ole-Morten Duesund 2026-04-07 10:47:13 +02:00
commit e379039fe8
5 changed files with 54 additions and 37 deletions

View file

@ -97,6 +97,29 @@ func (s *FaveStore) Delete(id int64) error {
return nil
}
// ImagePathsByUser returns all non-empty image paths for a user's faves.
// Used for cleanup before user deletion.
func (s *FaveStore) ImagePathsByUser(userID int64) ([]string, error) {
rows, err := s.db.Query(
"SELECT image_path FROM faves WHERE user_id = ? AND image_path != ''",
userID,
)
if err != nil {
return nil, err
}
defer rows.Close()
var paths []string
for rows.Next() {
var p string
if err := rows.Scan(&p); err != nil {
return nil, err
}
paths = append(paths, p)
}
return paths, rows.Err()
}
// ListByUser returns all faves for a user (both public and private),
// ordered by newest first, with pagination.
func (s *FaveStore) ListByUser(userID int64, limit, offset int) ([]*model.Fave, int, error) {