mirror of
https://github.com/nkanaev/yarr.git
synced 2025-09-13 09:55:36 +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)
|
||||
|
@@ -62,8 +62,11 @@ create trigger if not exists del_item_search after delete on items begin
|
||||
delete from search where rowid = old.search_rowid;
|
||||
end;
|
||||
|
||||
create table if not exists http_state (
|
||||
url string not null primary key,
|
||||
create table if not exists http_states (
|
||||
feed_id references feeds(id) unique,
|
||||
last_refreshed datetime not null,
|
||||
|
||||
-- http header fields --
|
||||
last_modified string not null,
|
||||
etag string not null
|
||||
);
|
||||
|
Reference in New Issue
Block a user