Skip to content

Commit

Permalink
refactor(datastore): Set PullFeeds entries read status argument to be…
Browse files Browse the repository at this point in the history
… simpler bool instead of bool pointer
  • Loading branch information
bow committed Jan 20, 2024
1 parent f8f4973 commit 8b1a8d8
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
3 changes: 1 addition & 2 deletions cmd/feed_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ func newFeedPullCommand() *cobra.Command {
return err
}

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

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

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

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

for pr := range merge(chs) {
Expand Down Expand Up @@ -161,7 +161,7 @@ func pullFeedEntries(
tx *sql.Tx,
pk pullKey,
parser Parser,
entryReadStatus *bool,
onlyUnread bool,
) chan entity.PullResult {

pullTime := time.Now().UTC()
Expand All @@ -188,6 +188,11 @@ func pullFeedEntries(
return pk.err(err)
}

var entryReadStatus *bool
if onlyUnread {
entryReadStatus = pointer(false)
}

entries, err := getEntries(ctx, tx, []ID{pk.feedID}, entryReadStatus, nil)
if err != nil {
return pk.err(err)
Expand Down
16 changes: 8 additions & 8 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, nil)
c := db.PullFeeds(context.Background(), nil, true)
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, nil)
c := db.PullFeeds(context.Background(), nil, true)

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, pointer(false))
c := db.PullFeeds(context.Background(), nil, true)

got := make([]entity.PullResult, 0)
for res := range c {
Expand All @@ -204,12 +204,12 @@ func TestPullFeedsAllOkNoNewEntries(t *testing.T) {
a.ElementsMatch(want, got)
}

func TestPullFeedsAllOkSomeNewEntries(t *testing.T) {
func TestPullFeedsAllOkSomeNewEntriesAll(t *testing.T) {
t.Parallel()
a := assert.New(t)
db, dbFeeds, keys, pulledFeeds := setupComplexDBFixture(t)

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

got := make([]entity.PullResult, 0)
for res := range c {
Expand Down Expand Up @@ -310,12 +310,12 @@ func TestPullFeedsAllOkSomeNewEntries(t *testing.T) {
a.ElementsMatch(want, got)
}

func TestPullFeedsAllOkSomeNewEntriesUnread(t *testing.T) {
func TestPullFeedsAllOkSomeNewEntriesOnlyUnread(t *testing.T) {
t.Parallel()
a := assert.New(t)
db, dbFeeds, keys, pulledFeeds := setupComplexDBFixture(t)

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

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

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

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.

3 changes: 1 addition & 2 deletions internal/server/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ func (svc *service) PullFeeds(
}

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

for pr := range ch {
payload, err := convert(pr)
Expand Down

0 comments on commit 8b1a8d8

Please sign in to comment.