Add category feeds refresh
This commit is contained in:
parent
e12c263fc9
commit
ce35b46fee
8 changed files with 89 additions and 0 deletions
|
@ -43,6 +43,7 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
|
||||||
sr.HandleFunc("/categories/{categoryID}", handler.removeCategory).Methods(http.MethodDelete)
|
sr.HandleFunc("/categories/{categoryID}", handler.removeCategory).Methods(http.MethodDelete)
|
||||||
sr.HandleFunc("/categories/{categoryID}/mark-all-as-read", handler.markCategoryAsRead).Methods(http.MethodPut)
|
sr.HandleFunc("/categories/{categoryID}/mark-all-as-read", handler.markCategoryAsRead).Methods(http.MethodPut)
|
||||||
sr.HandleFunc("/categories/{categoryID}/feeds", handler.getCategoryFeeds).Methods(http.MethodGet)
|
sr.HandleFunc("/categories/{categoryID}/feeds", handler.getCategoryFeeds).Methods(http.MethodGet)
|
||||||
|
sr.HandleFunc("/categories/{categoryID}/refresh", handler.refreshCategory).Methods(http.MethodPut)
|
||||||
sr.HandleFunc("/categories/{categoryID}/entries", handler.getCategoryEntries).Methods(http.MethodGet)
|
sr.HandleFunc("/categories/{categoryID}/entries", handler.getCategoryEntries).Methods(http.MethodGet)
|
||||||
sr.HandleFunc("/categories/{categoryID}/entries/{entryID}", handler.getCategoryEntry).Methods(http.MethodGet)
|
sr.HandleFunc("/categories/{categoryID}/entries/{entryID}", handler.getCategoryEntry).Methods(http.MethodGet)
|
||||||
sr.HandleFunc("/discover", handler.discoverSubscriptions).Methods(http.MethodPost)
|
sr.HandleFunc("/discover", handler.discoverSubscriptions).Methods(http.MethodPost)
|
||||||
|
|
|
@ -123,3 +123,20 @@ func (h *handler) removeCategory(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
json.NoContent(w, r)
|
json.NoContent(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) {
|
||||||
|
userID := request.UserID(r)
|
||||||
|
categoryID := request.RouteInt64Param(r, "categoryID")
|
||||||
|
|
||||||
|
jobs, err := h.store.NewCategoryBatch(userID, categoryID, h.store.CountFeeds(userID))
|
||||||
|
if err != nil {
|
||||||
|
json.ServerError(w, r, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
h.pool.Push(jobs)
|
||||||
|
}()
|
||||||
|
|
||||||
|
json.NoContent(w, r)
|
||||||
|
}
|
||||||
|
|
|
@ -248,6 +248,12 @@ func (c *Client) DeleteCategory(categoryID int64) error {
|
||||||
return c.request.Delete(fmt.Sprintf("/v1/categories/%d", categoryID))
|
return c.request.Delete(fmt.Sprintf("/v1/categories/%d", categoryID))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RefreshCategory refreshes a category.
|
||||||
|
func (c *Client) RefreshCategory(categoryID int64) error {
|
||||||
|
_, err := c.request.Put(fmt.Sprintf("/v1/categories/%d/refresh", categoryID), nil)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Feeds gets all feeds.
|
// Feeds gets all feeds.
|
||||||
func (c *Client) Feeds() (Feeds, error) {
|
func (c *Client) Feeds() (Feeds, error) {
|
||||||
body, err := c.request.Get("/v1/feeds")
|
body, err := c.request.Get("/v1/feeds")
|
||||||
|
|
|
@ -45,6 +45,23 @@ func (s *Storage) NewUserBatch(userID int64, batchSize int) (jobs model.JobList,
|
||||||
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID)
|
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewCategoryBatch returns a series of jobs but only for a given category.
|
||||||
|
func (s *Storage) NewCategoryBatch(userID int64, categoryID int64, batchSize int) (jobs model.JobList, err error) {
|
||||||
|
// We do not take the error counter into consideration when the given
|
||||||
|
// user refresh manually all his feeds to force a refresh.
|
||||||
|
query := `
|
||||||
|
SELECT
|
||||||
|
id,
|
||||||
|
user_id
|
||||||
|
FROM
|
||||||
|
feeds
|
||||||
|
WHERE
|
||||||
|
user_id=$1 AND category_id=$2 AND disabled is false
|
||||||
|
ORDER BY next_check_at ASC LIMIT %d
|
||||||
|
`
|
||||||
|
return s.fetchBatchRows(fmt.Sprintf(query, batchSize), userID, categoryID)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Storage) fetchBatchRows(query string, args ...interface{}) (jobs model.JobList, err error) {
|
func (s *Storage) fetchBatchRows(query string, args ...interface{}) (jobs model.JobList, err error) {
|
||||||
rows, err := s.db.Query(query, args...)
|
rows, err := s.db.Query(query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -36,6 +36,9 @@
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ route "categoryFeeds" "categoryID" .category.ID }}">{{ icon "feeds" }}{{ t "menu.feeds" }}</a>
|
<a href="{{ route "categoryFeeds" "categoryID" .category.ID }}">{{ icon "feeds" }}{{ t "menu.feeds" }}</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="{{ route "refreshCategoryEntriesPage" "categoryID" .category.ID }}">{{ icon "refresh" }}{{ t "menu.refresh_all_feeds" }}</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,9 @@
|
||||||
data-url="{{ route "removeCategory" "categoryID" .category.ID }}">{{ icon "delete" }}{{ t "action.remove" }}</a>
|
data-url="{{ route "removeCategory" "categoryID" .category.ID }}">{{ icon "delete" }}{{ t "action.remove" }}</a>
|
||||||
</li>
|
</li>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
<li>
|
||||||
|
<a href="{{ route "refreshCategoryFeedsPage" "categoryID" .category.ID }}">{{ icon "refresh" }}{{ t "menu.refresh_all_feeds" }}</a>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
40
ui/category_refresh.go
Normal file
40
ui/category_refresh.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
||||||
|
// Use of this source code is governed by the Apache 2.0
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package ui // import "miniflux.app/ui"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"miniflux.app/http/request"
|
||||||
|
"miniflux.app/http/response/html"
|
||||||
|
"miniflux.app/http/route"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (h *handler) refreshCategoryEntriesPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
categoryID := h.refreshCategory(w, r)
|
||||||
|
html.Redirect(w, r, route.Path(h.router, "categoryEntries", "categoryID", categoryID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) refreshCategoryFeedsPage(w http.ResponseWriter, r *http.Request) {
|
||||||
|
categoryID := h.refreshCategory(w, r)
|
||||||
|
html.Redirect(w, r, route.Path(h.router, "categoryFeeds", "categoryID", categoryID))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h *handler) refreshCategory(w http.ResponseWriter, r *http.Request) int64 {
|
||||||
|
userID := request.UserID(r)
|
||||||
|
categoryID := request.RouteInt64Param(r, "categoryID")
|
||||||
|
|
||||||
|
jobs, err := h.store.NewCategoryBatch(userID, categoryID, h.store.CountFeeds(userID))
|
||||||
|
if err != nil {
|
||||||
|
html.ServerError(w, r, err)
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
h.pool.Push(jobs)
|
||||||
|
}()
|
||||||
|
|
||||||
|
return categoryID
|
||||||
|
}
|
2
ui/ui.go
2
ui/ui.go
|
@ -83,7 +83,9 @@ func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
|
||||||
uiRouter.HandleFunc("/category/create", handler.showCreateCategoryPage).Name("createCategory").Methods(http.MethodGet)
|
uiRouter.HandleFunc("/category/create", handler.showCreateCategoryPage).Name("createCategory").Methods(http.MethodGet)
|
||||||
uiRouter.HandleFunc("/category/save", handler.saveCategory).Name("saveCategory").Methods(http.MethodPost)
|
uiRouter.HandleFunc("/category/save", handler.saveCategory).Name("saveCategory").Methods(http.MethodPost)
|
||||||
uiRouter.HandleFunc("/category/{categoryID}/feeds", handler.showCategoryFeedsPage).Name("categoryFeeds").Methods(http.MethodGet)
|
uiRouter.HandleFunc("/category/{categoryID}/feeds", handler.showCategoryFeedsPage).Name("categoryFeeds").Methods(http.MethodGet)
|
||||||
|
uiRouter.HandleFunc("/category/{categoryID}/feeds/refresh", handler.refreshCategoryFeedsPage).Name("refreshCategoryFeedsPage").Methods(http.MethodGet)
|
||||||
uiRouter.HandleFunc("/category/{categoryID}/entries", handler.showCategoryEntriesPage).Name("categoryEntries").Methods(http.MethodGet)
|
uiRouter.HandleFunc("/category/{categoryID}/entries", handler.showCategoryEntriesPage).Name("categoryEntries").Methods(http.MethodGet)
|
||||||
|
uiRouter.HandleFunc("/category/{categoryID}/entries/refresh", handler.refreshCategoryEntriesPage).Name("refreshCategoryEntriesPage").Methods(http.MethodGet)
|
||||||
uiRouter.HandleFunc("/category/{categoryID}/entries/all", handler.showCategoryEntriesAllPage).Name("categoryEntriesAll").Methods(http.MethodGet)
|
uiRouter.HandleFunc("/category/{categoryID}/entries/all", handler.showCategoryEntriesAllPage).Name("categoryEntriesAll").Methods(http.MethodGet)
|
||||||
uiRouter.HandleFunc("/category/{categoryID}/edit", handler.showEditCategoryPage).Name("editCategory").Methods(http.MethodGet)
|
uiRouter.HandleFunc("/category/{categoryID}/edit", handler.showEditCategoryPage).Name("editCategory").Methods(http.MethodGet)
|
||||||
uiRouter.HandleFunc("/category/{categoryID}/update", handler.updateCategory).Name("updateCategory").Methods(http.MethodPost)
|
uiRouter.HandleFunc("/category/{categoryID}/update", handler.updateCategory).Name("updateCategory").Methods(http.MethodPost)
|
||||||
|
|
Loading…
Reference in a new issue