(app *App, u *User, w http.ResponseWriter, r *http.Request)
| 709 | } |
| 710 | |
| 711 | func viewMyPostsAPI(app *App, u *User, w http.ResponseWriter, r *http.Request) error { |
| 712 | reqJSON := IsJSON(r) |
| 713 | if !reqJSON { |
| 714 | return ErrBadRequestedType |
| 715 | } |
| 716 | |
| 717 | isAnonPosts := r.FormValue("anonymous") == "1" |
| 718 | if isAnonPosts { |
| 719 | pageStr := r.FormValue("page") |
| 720 | pg, err := strconv.Atoi(pageStr) |
| 721 | if err != nil { |
| 722 | log.Error("Error parsing page parameter '%s': %s", pageStr, err) |
| 723 | pg = 1 |
| 724 | } |
| 725 | |
| 726 | p, err := app.db.GetAnonymousPosts(u, pg) |
| 727 | if err != nil { |
| 728 | return err |
| 729 | } |
| 730 | return impart.WriteSuccess(w, p, http.StatusOK) |
| 731 | } |
| 732 | |
| 733 | var err error |
| 734 | p := GetPostsCache(u.ID) |
| 735 | if p == nil { |
| 736 | userPostsCache.Lock() |
| 737 | if userPostsCache.users[u.ID].ready == nil { |
| 738 | userPostsCache.users[u.ID] = postsCacheItem{ready: make(chan struct{})} |
| 739 | userPostsCache.Unlock() |
| 740 | |
| 741 | p, err = app.db.GetUserPosts(u) |
| 742 | if err != nil { |
| 743 | return err |
| 744 | } |
| 745 | |
| 746 | CachePosts(u.ID, p) |
| 747 | } else { |
| 748 | userPostsCache.Unlock() |
| 749 | |
| 750 | <-userPostsCache.users[u.ID].ready |
| 751 | p = GetPostsCache(u.ID) |
| 752 | } |
| 753 | } |
| 754 | |
| 755 | return impart.WriteSuccess(w, p, http.StatusOK) |
| 756 | } |
| 757 | |
| 758 | func viewMyCollectionsAPI(app *App, u *User, w http.ResponseWriter, r *http.Request) error { |
| 759 | reqJSON := IsJSON(r) |
nothing calls this directly
no test coverage detected