Skip to content

Commit

Permalink
feat(datastore): Add argument to filter on read status in PullFeeds
Browse files Browse the repository at this point in the history
  • Loading branch information
bow committed Jan 19, 2024
1 parent df6e31b commit 3546b17
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 19 deletions.
3 changes: 2 additions & 1 deletion cmd/feed_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,12 @@ func newFeedPullCommand() *cobra.Command {
return err
}

entriesReadStatus := false
var (
errs []error
n int
s = newPullSpinner(rawIDs)
ch = db.PullFeeds(cmd.Context(), ids)
ch = db.PullFeeds(cmd.Context(), ids, &entriesReadStatus)
)

s.Start()
Expand Down
1 change: 1 addition & 0 deletions internal/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Datastore interface {
PullFeeds(
ctx context.Context,
ids []entity.ID,
isRead *bool,
) (
results <-chan entity.PullResult,
)
Expand Down
9 changes: 5 additions & 4 deletions internal/datastore/sqlite_pull_feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
func (db *SQLite) PullFeeds(
ctx context.Context,
ids []entity.ID,
entryReadStatus *bool,
) <-chan entity.PullResult {

var (
Expand Down Expand Up @@ -48,7 +49,7 @@ func (db *SQLite) PullFeeds(

chs := make([]<-chan entity.PullResult, len(pks))
for i, pk := range pks {
chs[i] = pullNewFeedEntries(ctx, tx, pk, db.parser)
chs[i] = pullFeedEntries(ctx, tx, pk, db.parser, entryReadStatus)
}

for pr := range merge(chs) {
Expand Down Expand Up @@ -155,11 +156,12 @@ func getAllPullKeys(ctx context.Context, tx *sql.Tx) ([]pullKey, error) {
return pks, nil
}

func pullNewFeedEntries(
func pullFeedEntries(
ctx context.Context,
tx *sql.Tx,
pk pullKey,
parser Parser,
entryReadStatus *bool,
) chan entity.PullResult {

pullTime := time.Now().UTC()
Expand All @@ -186,8 +188,7 @@ func pullNewFeedEntries(
return pk.err(err)
}

defaultReadStatus := false
unreadEntries, err := getEntries(ctx, tx, []ID{pk.feedID}, &defaultReadStatus, nil)
unreadEntries, err := getEntries(ctx, tx, []ID{pk.feedID}, entryReadStatus, nil)
if err != nil {
return pk.err(err)
}
Expand Down
10 changes: 5 additions & 5 deletions internal/datastore/sqlite_pull_feeds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestPullFeedsAllOkEmptyDB(t *testing.T) {
ParseURLWithContext(gomock.Any(), gomock.Any()).
MaxTimes(0)

c := db.PullFeeds(context.Background(), nil)
c := db.PullFeeds(context.Background(), nil, nil)
a.Empty(c)
}

Expand Down Expand Up @@ -69,7 +69,7 @@ func TestPullFeedsAllOkEmptyEntries(t *testing.T) {
MaxTimes(1).
Return(toGFeed(t, dbFeeds[1]), nil)

c := db.PullFeeds(context.Background(), nil)
c := db.PullFeeds(context.Background(), nil, nil)

got := make([]entity.PullResult, 0)
for res := range c {
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestPullFeedsAllOkNoNewEntries(t *testing.T) {
MaxTimes(1).
Return(toGFeed(t, pulledFeeds[1]), nil)

c := db.PullFeeds(context.Background(), nil)
c := db.PullFeeds(context.Background(), nil, pointer(false))

got := make([]entity.PullResult, 0)
for res := range c {
Expand Down Expand Up @@ -324,7 +324,7 @@ func TestPullFeedsAllOkSomeNewEntries(t *testing.T) {
MaxTimes(1).
Return(toGFeed(t, pulledFeeds[1]), nil)

c := db.PullFeeds(context.Background(), nil)
c := db.PullFeeds(context.Background(), nil, pointer(false))

got := make([]entity.PullResult, 0)
for res := range c {
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestPullFeedsSelectedOkSomeNewEntries(t *testing.T) {
MaxTimes(1).
Return(toGFeed(t, pulledFeed), nil)

c := db.PullFeeds(context.Background(), []ID{keys[pulledFeed.title].ID})
c := db.PullFeeds(context.Background(), []ID{keys[pulledFeed.title].ID}, pointer(false))

got := make([]entity.PullResult, 0)
for res := range c {
Expand Down
8 changes: 4 additions & 4 deletions internal/server/datastore_mock_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion internal/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func (svc *service) PullFeeds(
ids[i] = id
}

ch := svc.ds.PullFeeds(stream.Context(), ids)
// TODO: Expose isRead in proto.
isRead := false
ch := svc.ds.PullFeeds(stream.Context(), ids, &isRead)

for pr := range ch {
payload, err := convert(pr)
Expand Down
8 changes: 4 additions & 4 deletions internal/server/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func TestPullFeedsAllOk(t *testing.T) {
}()

ds.EXPECT().
PullFeeds(gomock.Any(), []entity.ID{}).
PullFeeds(gomock.Any(), []entity.ID{}, gomock.Any()).
Return(ch)

req := api.PullFeedsRequest{}
Expand Down Expand Up @@ -354,7 +354,7 @@ func TestPullFeedsSelectedAllOk(t *testing.T) {
}()

ds.EXPECT().
PullFeeds(gomock.Any(), []entity.ID{2, 3}).
PullFeeds(gomock.Any(), []entity.ID{2, 3}, gomock.Any()).
Return(ch)

req := api.PullFeedsRequest{FeedIds: []uint32{2, 3}}
Expand Down Expand Up @@ -444,7 +444,7 @@ func TestPullFeedsErrSomeFeed(t *testing.T) {
}()

ds.EXPECT().
PullFeeds(gomock.Any(), []entity.ID{}).
PullFeeds(gomock.Any(), []entity.ID{}, gomock.Any()).
Return(ch)

req := api.PullFeedsRequest{}
Expand Down Expand Up @@ -542,7 +542,7 @@ func TestPullFeedsErrNonFeed(t *testing.T) {
}()

ds.EXPECT().
PullFeeds(gomock.Any(), []entity.ID{}).
PullFeeds(gomock.Any(), []entity.ID{}, gomock.Any()).
Return(ch)

req := api.PullFeedsRequest{}
Expand Down

0 comments on commit 3546b17

Please sign in to comment.