diff --git a/cmd/open.go b/cmd/open.go index 7554064..e94368d 100644 --- a/cmd/open.go +++ b/cmd/open.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - db "github.com/RadhiFadlillah/shiori/database" "github.com/spf13/cobra" "os/exec" "strings" @@ -50,7 +49,7 @@ func init() { func openBookmarks(args ...string) { // Read bookmarks from database - bookmarks, err := DB.GetBookmarks(db.GetBookmarksOptions{}, args...) + bookmarks, err := DB.GetBookmarks(false, args...) if err != nil { cError.Println(err) return @@ -76,9 +75,7 @@ func openBookmarks(args ...string) { func openBookmarksCache(trimSpace bool, args ...string) { // Read bookmark content from database - bookmarks, err := DB.GetBookmarks( - db.GetBookmarksOptions{WithContents: true}, - args...) + bookmarks, err := DB.GetBookmarks(true, args...) if err != nil { cError.Println(err) return diff --git a/cmd/print.go b/cmd/print.go index fa5d18c..24a3d27 100644 --- a/cmd/print.go +++ b/cmd/print.go @@ -3,7 +3,6 @@ package cmd import ( "encoding/json" "fmt" - db "github.com/RadhiFadlillah/shiori/database" "github.com/RadhiFadlillah/shiori/model" "github.com/spf13/cobra" "os" @@ -23,7 +22,7 @@ var ( indexOnly, _ := cmd.Flags().GetBool("index-only") // Read bookmarks from database - bookmarks, err := DB.GetBookmarks(db.GetBookmarksOptions{}, args...) + bookmarks, err := DB.GetBookmarks(false, args...) if err != nil { cError.Println(err) os.Exit(1) diff --git a/cmd/serve.go b/cmd/serve.go index 4dd26e3..745fda7 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -4,7 +4,6 @@ import ( "crypto/rand" "encoding/json" "fmt" - db "github.com/RadhiFadlillah/shiori/database" "github.com/RadhiFadlillah/shiori/model" "github.com/dgrijalva/jwt-go" "github.com/dgrijalva/jwt-go/request" @@ -99,7 +98,7 @@ func serveBookmarkCache(w http.ResponseWriter, r *http.Request, ps httprouter.Pa id := ps.ByName("id") // Read bookmarks - bookmarks, err := DB.GetBookmarks(db.GetBookmarksOptions{WithContents: true}, id) + bookmarks, err := DB.GetBookmarks(true, id) checkError(err) if len(bookmarks) == 0 { @@ -159,7 +158,7 @@ func apiGetBookmarks(w http.ResponseWriter, r *http.Request, ps httprouter.Param checkError(err) // Fetch all bookmarks - bookmarks, err := DB.GetBookmarks(db.GetBookmarksOptions{OrderLatest: true}) + bookmarks, err := DB.GetBookmarks(false) checkError(err) err = json.NewEncoder(w).Encode(&bookmarks) diff --git a/cmd/update.go b/cmd/update.go index 531627b..00d7ae0 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -3,7 +3,6 @@ package cmd import ( "fmt" "github.com/RadhiFadlillah/go-readability" - db "github.com/RadhiFadlillah/shiori/database" "github.com/RadhiFadlillah/shiori/model" "github.com/spf13/cobra" "html/template" @@ -84,7 +83,7 @@ func init() { func updateBookmarks(indices []string, url, title, excerpt string, tags []string, offline bool) ([]model.Bookmark, error) { mutex := sync.Mutex{} // Read bookmarks from database - bookmarks, err := DB.GetBookmarks(db.GetBookmarksOptions{WithContents: true}, indices...) + bookmarks, err := DB.GetBookmarks(true, indices...) if err != nil { return []model.Bookmark{}, err } diff --git a/database/database.go b/database/database.go index 5922ad7..a089af2 100644 --- a/database/database.go +++ b/database/database.go @@ -11,7 +11,7 @@ type Database interface { CreateBookmark(bookmark model.Bookmark) (int64, error) // GetBookmarks fetch list of bookmarks based on submitted indices. - GetBookmarks(options GetBookmarksOptions, indices ...string) ([]model.Bookmark, error) + GetBookmarks(withContent bool, indices ...string) ([]model.Bookmark, error) // DeleteBookmarks removes all record with matching indices from database. DeleteBookmarks(indices ...string) ([]int, []int, error) @@ -32,11 +32,6 @@ type Database interface { DeleteAccounts(usernames ...string) error } -type GetBookmarksOptions struct { - WithContents bool - OrderLatest bool -} - func checkError(err error) { if err != nil && err != sql.ErrNoRows { panic(err) diff --git a/database/sqlite.go b/database/sqlite.go index 7beb7e9..ffae0a9 100644 --- a/database/sqlite.go +++ b/database/sqlite.go @@ -161,7 +161,7 @@ func (db *SQLiteDatabase) CreateBookmark(bookmark model.Bookmark) (bookmarkID in } // GetBookmarks fetch list of bookmarks based on submitted indices. -func (db *SQLiteDatabase) GetBookmarks(options GetBookmarksOptions, indices ...string) ([]model.Bookmark, error) { +func (db *SQLiteDatabase) GetBookmarks(withContent bool, indices ...string) ([]model.Bookmark, error) { // Convert list of index to int listIndex := []int{} errInvalidIndex := fmt.Errorf("Index is not valid") @@ -213,10 +213,6 @@ func (db *SQLiteDatabase) GetBookmarks(options GetBookmarksOptions, indices ...s min_read_time, max_read_time, modified FROM bookmark` + whereClause - if options.OrderLatest { - query += ` ORDER BY modified DESC` - } - bookmarks := []model.Bookmark{} err := db.Select(&bookmarks, query, args...) if err != nil && err != sql.ErrNoRows { @@ -246,7 +242,7 @@ func (db *SQLiteDatabase) GetBookmarks(options GetBookmarksOptions, indices ...s return nil, err } - if options.WithContents { + if withContent { err = stmtGetContent.Get(&book, book.ID) if err != nil && err != sql.ErrNoRows { return nil, err