diff --git a/appview/db/repos.go b/appview/db/repos.go
index a8d5008..b0f9202 100644
--- a/appview/db/repos.go
+++ b/appview/db/repos.go
@@ -13,6 +13,9 @@ type Repo struct {
Created time.Time
AtUri string
Description string
+
+ // optionally, populate this when querying for reverse mappings
+ RepoStats *RepoStats
}
func GetAllRepos(e Execer, limit int) ([]Repo, error) {
@@ -52,7 +55,23 @@ func GetAllRepos(e Execer, limit int) ([]Repo, error) {
func GetAllReposByDid(e Execer, did string) ([]Repo, error) {
var repos []Repo
- rows, err := e.Query(`select did, name, knot, rkey, description, created from repos where did = ?`, did)
+ rows, err := e.Query(
+ `select
+ r.did,
+ r.name,
+ r.knot,
+ r.rkey,
+ r.description,
+ r.created,
+ count(s.id) as star_count
+ from
+ repos r
+ left join
+ stars s on r.at_uri = s.repo_at
+ where
+ r.did = ?
+ group by
+ r.at_uri`, did)
if err != nil {
return nil, err
}
@@ -60,10 +79,30 @@ func GetAllReposByDid(e Execer, did string) ([]Repo, error) {
for rows.Next() {
var repo Repo
- err := scanRepo(rows, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &repo.Description, &repo.Created)
+ var repoStats RepoStats
+ var createdAt string
+ var nullableDescription sql.NullString
+
+ err := rows.Scan(&repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &createdAt, &repoStats.StarCount)
if err != nil {
return nil, err
}
+
+ if nullableDescription.Valid {
+ repo.Description = nullableDescription.String
+ } else {
+ repo.Description = ""
+ }
+
+ createdAtTime, err := time.Parse(time.RFC3339, createdAt)
+ if err != nil {
+ repo.Created = time.Now()
+ } else {
+ repo.Created = createdAtTime
+ }
+
+ repo.RepoStats = &repoStats
+
repos = append(repos, repo)
}
@@ -150,7 +189,19 @@ func UpdateDescription(e Execer, repoAt, newDescription string) error {
func CollaboratingIn(e Execer, collaborator string) ([]Repo, error) {
var repos []Repo
- rows, err := e.Query(`select r.did, r.name, r.knot, r.rkey, r.description, r.created from repos r join collaborators c on r.id = c.repo where c.did = ?;`, collaborator)
+ rows, err := e.Query(
+ `select
+ r.did, r.name, r.knot, r.rkey, r.description, r.created, count(s.id) as star_count
+ from
+ repos r
+ join
+ collaborators c on r.id = c.repo
+ left join
+ stars s on r.at_uri = s.repo_at
+ where
+ c.did = ?
+ group by
+ r.id;`, collaborator)
if err != nil {
return nil, err
}
@@ -158,10 +209,30 @@ func CollaboratingIn(e Execer, collaborator string) ([]Repo, error) {
for rows.Next() {
var repo Repo
- err := scanRepo(rows, &repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &repo.Description, &repo.Created)
+ var repoStats RepoStats
+ var createdAt string
+ var nullableDescription sql.NullString
+
+ err := rows.Scan(&repo.Did, &repo.Name, &repo.Knot, &repo.Rkey, &nullableDescription, &createdAt, &repoStats.StarCount)
if err != nil {
return nil, err
}
+
+ if nullableDescription.Valid {
+ repo.Description = nullableDescription.String
+ } else {
+ repo.Description = ""
+ }
+
+ createdAtTime, err := time.Parse(time.RFC3339, createdAt)
+ if err != nil {
+ repo.Created = time.Now()
+ } else {
+ repo.Created = createdAtTime
+ }
+
+ repo.RepoStats = &repoStats
+
repos = append(repos, repo)
}
diff --git a/appview/db/star.go b/appview/db/star.go
index 84b04e7..334a1ba 100644
--- a/appview/db/star.go
+++ b/appview/db/star.go
@@ -10,9 +10,11 @@ import (
type Star struct {
StarredByDid string
RepoAt syntax.ATURI
- Repo *Repo
Created time.Time
Rkey string
+
+ // optionally, populate this when querying for reverse mappings
+ Repo *Repo
}
func (star *Star) ResolveRepo(e Execer) error {
diff --git a/appview/pages/pages.go b/appview/pages/pages.go
index cee8e62..a39357a 100644
--- a/appview/pages/pages.go
+++ b/appview/pages/pages.go
@@ -523,7 +523,12 @@ func (p *Pages) Static() http.Handler {
func Cache(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
- w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
+ if strings.HasSuffix(r.URL.Path, ".css") {
+ // on day for css files
+ w.Header().Set("Cache-Control", "public, max-age=86400")
+ } else {
+ w.Header().Set("Cache-Control", "public, max-age=31536000, immutable")
+ }
h.ServeHTTP(w, r)
})
}
diff --git a/appview/pages/templates/fragments/star.html b/appview/pages/templates/fragments/star.html
index 12041df..4af3545 100644
--- a/appview/pages/templates/fragments/star.html
+++ b/appview/pages/templates/fragments/star.html
@@ -22,9 +22,6 @@
{{ .Stats.StarCount }}
-
- loading
-