mirror of
https://github.com/nkanaev/yarr.git
synced 2025-12-15 08:37:21 +00:00
change http state storage
This commit is contained in:
@@ -1,32 +1,46 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
type HTTPState struct {
|
||||
LastModified string
|
||||
Etag string
|
||||
FeedID int64
|
||||
LastRefreshed time.Time
|
||||
|
||||
LastModified string
|
||||
Etag string
|
||||
}
|
||||
|
||||
func (s *Storage) GetHTTPState(url string) *HTTPState {
|
||||
func (s *Storage) GetHTTPState(feedID int64) *HTTPState {
|
||||
row := s.db.QueryRow(`
|
||||
select last_modified, etag
|
||||
from http_state where url = ?
|
||||
`, url)
|
||||
select feed_id, last_refreshed, last_modified, etag
|
||||
from http_states where feed_id = ?
|
||||
`, feedID)
|
||||
|
||||
if row == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
var state HTTPState
|
||||
row.Scan(&state.LastModified, &state.Etag)
|
||||
row.Scan(
|
||||
&state.FeedID,
|
||||
&state.LastRefreshed,
|
||||
&state.LastModified,
|
||||
&state.Etag,
|
||||
)
|
||||
return &state
|
||||
}
|
||||
|
||||
func (s *Storage) SetHTTPState(url string, state HTTPState) {
|
||||
func (s *Storage) SetHTTPState(feedID int64, lastModified, etag string) {
|
||||
_, err := s.db.Exec(`
|
||||
insert into http_state (url, last_modified, etag)
|
||||
values (?, ?, ?)
|
||||
on conflict (url) do update set last_modified = ?, etag = ?`,
|
||||
url, state.LastModified, state.Etag,
|
||||
state.LastModified, state.Etag,
|
||||
insert into http_states (feed_id, last_modified, etag, last_refreshed)
|
||||
values (?, ?, ?, datetime())
|
||||
on conflict (feed_id) do update set last_modified = ?, etag = ?, last_refreshed = datetime()`,
|
||||
// insert
|
||||
feedID, lastModified, etag,
|
||||
// upsert
|
||||
lastModified, etag,
|
||||
)
|
||||
if err != nil {
|
||||
s.log.Print(err)
|
||||
|
||||
Reference in New Issue
Block a user