1
0
Fork 0

Improve timezone handling

This commit is contained in:
Frédéric Guillot 2017-12-28 19:20:14 -08:00
parent 519d4fcd73
commit a63105e13b
14 changed files with 50 additions and 48 deletions

View file

@ -27,7 +27,7 @@ func (c *Controller) GetFeedEntry(ctx *core.Context, request *core.Request, resp
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithFeedID(feedID)
builder.WithEntryID(entryID)
@ -54,7 +54,7 @@ func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithEntryID(entryID)
entry, err := builder.GetEntry()
@ -107,7 +107,7 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithFeedID(feedID)
builder.WithStatus(status)
builder.WithOrder(order)
@ -161,7 +161,7 @@ func (c *Controller) GetEntries(ctx *core.Context, request *core.Request, respon
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithStatus(status)
builder.WithOrder(order)
builder.WithDirection(direction)

View file

@ -336,10 +336,9 @@ func (c *Controller) handleItems(ctx *core.Context, request *core.Request, respo
var result itemsResponse
userID := ctx.UserID()
timezone := ctx.UserTimezone()
logger.Debug("[Fever] Fetching items for userID=%d", userID)
builder := c.store.GetEntryQueryBuilder(userID, timezone)
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithoutStatus(model.EntryStatusRemoved)
builder.WithLimit(50)
builder.WithOrder("id")
@ -374,7 +373,7 @@ func (c *Controller) handleItems(ctx *core.Context, request *core.Request, respo
return
}
builder = c.store.GetEntryQueryBuilder(userID, timezone)
builder = c.store.NewEntryQueryBuilder(userID)
builder.WithoutStatus(model.EntryStatusRemoved)
result.Total, err = builder.CountEntries()
if err != nil {
@ -421,7 +420,7 @@ func (c *Controller) handleUnreadItems(ctx *core.Context, request *core.Request,
userID := ctx.UserID()
logger.Debug("[Fever] Fetching unread items for userID=%d", userID)
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithStatus(model.EntryStatusUnread)
entries, err := builder.GetEntries()
if err != nil {
@ -452,7 +451,7 @@ func (c *Controller) handleSavedItems(ctx *core.Context, request *core.Request,
userID := ctx.UserID()
logger.Debug("[Fever] Fetching saved items for userID=%d", userID)
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithStarred()
entryIDs, err := builder.GetEntryIDs()
@ -512,7 +511,7 @@ func (c *Controller) handleWriteItems(ctx *core.Context, request *core.Request,
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -566,7 +565,7 @@ func (c *Controller) handleWriteFeeds(ctx *core.Context, request *core.Request,
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithStatus(model.EntryStatusUnread)
builder.WithFeedID(feedID)
@ -606,7 +605,7 @@ func (c *Controller) handleWriteGroups(ctx *core.Context, request *core.Request,
return
}
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
builder := c.store.NewEntryQueryBuilder(userID)
builder.WithStatus(model.EntryStatusUnread)
builder.WithCategoryID(groupID)

View file

@ -67,7 +67,7 @@
<div class="panel">
<ul>
<li><strong>{{ t "Last checked:" }} </strong>{{ isodate .feed.CheckedAt }}</li>
<li><strong>{{ t "Last checked:" }} </strong><time datetime="{{ isodate .feed.CheckedAt }}" title="{{ isodate .feed.CheckedAt }}">{{ elapsed .feed.CheckedAt }}</time></li>
<li><strong>{{ t "ETag header:" }} </strong>{{ if .feed.EtagHeader }}{{ .feed.EtagHeader }}{{ else }}{{ t "None" }}{{ end }}</li>
<li><strong>{{ t "LastModified header:" }} </strong>{{ if .feed.LastModifiedHeader }}{{ .feed.LastModifiedHeader }}{{ else }}{{ t "None" }}{{ end }}</li>
</ul>

View file

@ -1,5 +1,5 @@
// Code generated by go generate; DO NOT EDIT.
// 2017-12-28 18:55:07.399522774 -0800 PST m=+0.026243360
// 2017-12-28 19:08:21.190684499 -0800 PST m=+0.036802540
package template
@ -432,7 +432,7 @@ var templateViewsMap = map[string]string{
<div class="panel">
<ul>
<li><strong>{{ t "Last checked:" }} </strong>{{ isodate .feed.CheckedAt }}</li>
<li><strong>{{ t "Last checked:" }} </strong><time datetime="{{ isodate .feed.CheckedAt }}" title="{{ isodate .feed.CheckedAt }}">{{ elapsed .feed.CheckedAt }}</time></li>
<li><strong>{{ t "ETag header:" }} </strong>{{ if .feed.EtagHeader }}{{ .feed.EtagHeader }}{{ else }}{{ t "None" }}{{ end }}</li>
<li><strong>{{ t "LastModified header:" }} </strong>{{ if .feed.LastModifiedHeader }}{{ .feed.LastModifiedHeader }}{{ else }}{{ t "None" }}{{ end }}</li>
</ul>
@ -1339,7 +1339,7 @@ var templateViewsMapChecksums = map[string]string{
"create_category": "2b82af5d2dcd67898dc5daa57a6461e6ff8121a6089b2a2a1be909f35e4a2275",
"create_user": "45e226df757126d5fe7c464e295e9a34f07952cfdb71e31e49839850d35af139",
"edit_category": "cee720faadcec58289b707ad30af623d2ee66c1ce23a732965463250d7ff41c5",
"edit_feed": "05bc3dc7316bd3b0ef4d8fa23ab585a990fded98ed433ee57b878fb1c7b5a4c0",
"edit_feed": "15f19ab44057fca1630c6860d5951d6073f82f83ad682a176c475591c6f26377",
"edit_user": "82d9749d76ddbd2352816d813c4b1f6d92f2222de678b4afe5821090246735c7",
"entry": "6b4405e0c8e4a7d31874659f8835f4e43e01dc3c20686091517ac750196dd70f",
"feed_entries": "ac93cb9a90f93ddd9dd8a67d7e160592ecb9f5e465ee9679bb14eecd8d4caf20",

View file

@ -51,7 +51,7 @@ func (c *Controller) ShowCategoryEntries(ctx *core.Context, request *core.Reques
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithCategoryID(category.ID)
builder.WithOrder(model.DefaultSortingOrder)
builder.WithDirection(user.EntryDirection)

View file

@ -35,7 +35,7 @@ type Controller struct {
func (c *Controller) getCommonTemplateArgs(ctx *core.Context) (tplParams, error) {
user := ctx.LoggedUser()
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusUnread)
countUnread, err := builder.CountEntries()

View file

@ -27,7 +27,7 @@ func (c *Controller) FetchContent(ctx *core.Context, request *core.Request, resp
}
user := ctx.LoggedUser()
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -63,7 +63,7 @@ func (c *Controller) SaveEntry(ctx *core.Context, request *core.Request, respons
}
user := ctx.LoggedUser()
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -107,7 +107,7 @@ func (c *Controller) ShowFeedEntry(ctx *core.Context, request *core.Request, res
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithFeedID(feedID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -138,7 +138,7 @@ func (c *Controller) ShowFeedEntry(ctx *core.Context, request *core.Request, res
return
}
builder = c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder = c.store.NewEntryQueryBuilder(user.ID)
builder.WithFeedID(feedID)
prevEntry, nextEntry, err := c.getEntryPrevNext(user, builder, entry.ID)
@ -183,7 +183,7 @@ func (c *Controller) ShowCategoryEntry(ctx *core.Context, request *core.Request,
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithCategoryID(categoryID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -214,7 +214,7 @@ func (c *Controller) ShowCategoryEntry(ctx *core.Context, request *core.Request,
return
}
builder = c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder = c.store.NewEntryQueryBuilder(user.ID)
builder.WithCategoryID(categoryID)
prevEntry, nextEntry, err := c.getEntryPrevNext(user, builder, entry.ID)
@ -253,7 +253,7 @@ func (c *Controller) ShowUnreadEntry(ctx *core.Context, request *core.Request, r
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -274,7 +274,7 @@ func (c *Controller) ShowUnreadEntry(ctx *core.Context, request *core.Request, r
return
}
builder = c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder = c.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusUnread)
prevEntry, nextEntry, err := c.getEntryPrevNext(user, builder, entry.ID)
@ -323,7 +323,7 @@ func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, res
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -344,7 +344,7 @@ func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, res
return
}
builder = c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder = c.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusRead)
prevEntry, nextEntry, err := c.getEntryPrevNext(user, builder, entry.ID)
@ -383,7 +383,7 @@ func (c *Controller) ShowStarredEntry(ctx *core.Context, request *core.Request,
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithEntryID(entryID)
builder.WithoutStatus(model.EntryStatusRemoved)
@ -413,7 +413,7 @@ func (c *Controller) ShowStarredEntry(ctx *core.Context, request *core.Request,
return
}
builder = c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder = c.store.NewEntryQueryBuilder(user.ID)
builder.WithStarred()
prevEntry, nextEntry, err := c.getEntryPrevNext(user, builder, entry.ID)

View file

@ -68,7 +68,7 @@ func (c *Controller) ShowFeedEntries(ctx *core.Context, request *core.Request, r
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithFeedID(feed.ID)
builder.WithoutStatus(model.EntryStatusRemoved)
builder.WithOrder(model.DefaultSortingOrder)

View file

@ -20,7 +20,7 @@ func (c *Controller) ShowHistoryPage(ctx *core.Context, request *core.Request, r
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusRead)
builder.WithOrder(model.DefaultSortingOrder)
builder.WithDirection(user.EntryDirection)

View file

@ -21,7 +21,7 @@ func (c *Controller) ShowStarredPage(ctx *core.Context, request *core.Request, r
return
}
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithoutStatus(model.EntryStatusRemoved)
builder.WithStarred()
builder.WithOrder(model.DefaultSortingOrder)

View file

@ -14,7 +14,7 @@ func (c *Controller) ShowUnreadPage(ctx *core.Context, request *core.Request, re
user := ctx.LoggedUser()
offset := request.QueryIntegerParam("offset", 0)
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder := c.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusUnread)
countUnread, err := builder.CountEntries()
if err != nil {
@ -26,7 +26,7 @@ func (c *Controller) ShowUnreadPage(ctx *core.Context, request *core.Request, re
offset = 0
}
builder = c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
builder = c.store.NewEntryQueryBuilder(user.ID)
builder.WithStatus(model.EntryStatusUnread)
builder.WithOrder(model.DefaultSortingOrder)
builder.WithDirection(user.EntryDirection)

View file

@ -16,9 +16,9 @@ import (
"github.com/lib/pq"
)
// GetEntryQueryBuilder returns a new EntryQueryBuilder
func (s *Storage) GetEntryQueryBuilder(userID int64, timezone string) *EntryQueryBuilder {
return NewEntryQueryBuilder(s, userID, timezone)
// NewEntryQueryBuilder returns a new EntryQueryBuilder
func (s *Storage) NewEntryQueryBuilder(userID int64) *EntryQueryBuilder {
return NewEntryQueryBuilder(s, userID)
}
// createEntry add a new entry.

View file

@ -20,7 +20,6 @@ type EntryQueryBuilder struct {
store *Storage
feedID int64
userID int64
timezone string
categoryID int64
status string
notStatus string
@ -157,7 +156,7 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) {
query := `
SELECT
e.id, e.user_id, e.feed_id, e.hash, e.published_at at time zone '%s', e.title,
e.id, e.user_id, e.feed_id, e.hash, e.published_at at time zone u.timezone, e.title,
e.url, e.author, e.content, e.status, e.starred,
f.title as feed_title, f.feed_url, f.site_url, f.checked_at,
f.category_id, c.title as category_title, f.scraper_rules, f.rewrite_rules, f.crawler,
@ -166,11 +165,12 @@ func (e *EntryQueryBuilder) GetEntries() (model.Entries, error) {
LEFT JOIN feeds f ON f.id=e.feed_id
LEFT JOIN categories c ON c.id=f.category_id
LEFT JOIN feed_icons fi ON fi.feed_id=f.id
LEFT JOIN users u ON u.id=e.user_id
WHERE %s %s
`
args, conditions := e.buildCondition()
query = fmt.Sprintf(query, e.timezone, conditions, e.buildSorting())
query = fmt.Sprintf(query, conditions, e.buildSorting())
// log.Println(query)
rows, err := e.store.db.Query(query, args...)
@ -342,11 +342,10 @@ func (e *EntryQueryBuilder) buildSorting() string {
}
// NewEntryQueryBuilder returns a new EntryQueryBuilder.
func NewEntryQueryBuilder(store *Storage, userID int64, timezone string) *EntryQueryBuilder {
func NewEntryQueryBuilder(store *Storage, userID int64) *EntryQueryBuilder {
return &EntryQueryBuilder{
store: store,
userID: userID,
timezone: timezone,
starred: false,
store: store,
userID: userID,
starred: false,
}
}

View file

@ -52,13 +52,15 @@ func (s *Storage) Feeds(userID int64) (model.Feeds, error) {
feeds := make(model.Feeds, 0)
query := `SELECT
f.id, f.feed_url, f.site_url, f.title, f.etag_header, f.last_modified_header,
f.user_id, f.checked_at, f.parsing_error_count, f.parsing_error_msg,
f.user_id, f.checked_at at time zone u.timezone,
f.parsing_error_count, f.parsing_error_msg,
f.scraper_rules, f.rewrite_rules, f.crawler,
f.category_id, c.title as category_title,
fi.icon_id
FROM feeds f
LEFT JOIN categories c ON c.id=f.category_id
LEFT JOIN feed_icons fi ON fi.feed_id=f.id
LEFT JOIN users u ON u.id=f.user_id
WHERE f.user_id=$1
ORDER BY f.parsing_error_count DESC, f.title ASC`
@ -117,13 +119,15 @@ func (s *Storage) FeedByID(userID, feedID int64) (*model.Feed, error) {
query := `
SELECT
f.id, f.feed_url, f.site_url, f.title, f.etag_header, f.last_modified_header,
f.user_id, f.checked_at, f.parsing_error_count, f.parsing_error_msg,
f.user_id, f.checked_at at time zone u.timezone,
f.parsing_error_count, f.parsing_error_msg,
f.scraper_rules, f.rewrite_rules, f.crawler,
f.category_id, c.title as category_title,
fi.icon_id
FROM feeds f
LEFT JOIN categories c ON c.id=f.category_id
LEFT JOIN feed_icons fi ON fi.feed_id=f.id
LEFT JOIN users u ON u.id=f.user_id
WHERE f.user_id=$1 AND f.id=$2`
err := s.db.QueryRow(query, userID, feedID).Scan(