~abyxcos/axolotlfeeds

2347225509898e01ca93de9b085b7fb7c22541d4 — abyxcos 1 year, 11 months ago d10e1b0
Silly bug with GetPostsByName only getting read or unread posts, we really need a sane option to get all or unread (trinary toggle).
4 files changed, 23 insertions(+), 6 deletions(-)

M axolotl/db.go
M axolotl/post.go
M axolotl/webfeeds.go
M main.go
M axolotl/db.go => axolotl/db.go +1 -1
@@ 49,7 49,7 @@ CREATE TABLE IF NOT EXISTS 'posts_%s'
	 folder			text,
	 name				text,
	 -- post data
	 uuid				text unique,
	 uuid				text,
	 url				text,
	 date				text,
	 title			text,

M axolotl/post.go => axolotl/post.go +14 -2
@@ 24,6 24,7 @@ type Post struct {
	Fetched bool `db:"fetched"`
}

// TODO: Rename to unread.
// Get a list of posts from our database by folder.
func (user User) GetPostsByFolder(folder string, read bool) ([]Post, error) {
	var posts []Post


@@ 33,6 34,7 @@ func (user User) GetPostsByFolder(folder string, read bool) ([]Post, error) {
	return posts, err
}

// TODO: Rename to unread.
// Get a list of posts from our database by folder + name.
func (user User) GetPostsByName(folder, name string, read bool) ([]Post, error) {
	var posts []Post


@@ 42,6 44,15 @@ func (user User) GetPostsByName(folder, name string, read bool) ([]Post, error) 
	return posts, err
}

// Get all posts from a feed
func (user User) GetAllPostsByFeed(feed Feed) ([]Post, error) {
	var posts []Post
	err := db.Select(&posts,
		fmt.Sprintf("SELECT * FROM posts_%s WHERE folder=$1 and name=$2", user.UUID),
		feed.Folder, feed.Name)
	return posts, err
}

// Get a single post from our database by uuid.
// TODO: uuid here is really id, not our feed-local "uuid".
func (user User) GetPostByID(uuid string) (Post, error) {


@@ 56,7 67,8 @@ func (user User) GetPostByID(uuid string) (Post, error) {
func (user User) AddPost(post Post) error {
	_, err := db.NamedExec(fmt.Sprintf(
		`INSERT INTO posts_%s (folder, name, uuid, url, date, title, text, rendered, image, caption, read, fetched)
		 VALUES (:folder, :name, :uuid, :url, :date, :title, :text, :rendered, :image, :caption, :read, :fetched)
		 VALUES (:folder, :name, :uuid, :url, :date, :title, :text, :rendered, :image, :caption, :read, :fetched)`, user.UUID), &post)
/*
			ON CONFLICT (uuid) DO UPDATE SET
				-- Post data
				url=excluded.url,


@@ 70,7 82,7 @@ func (user User) AddPost(post Post) error {
				read=excluded.read,
				fetched=excluded.fetched
			WHERE excluded.date>posts_%s.date`,
		user.UUID, user.UUID), &post)
*/
	return err
}


M axolotl/webfeeds.go => axolotl/webfeeds.go +3 -2
@@ 31,8 31,9 @@ func UpdateAllFeeds() error {
// Add any new posts to the database, and update any modified posts.
// Return an array of posts associated with it.
func (user User) UpdateFeed(feed Feed) error {
	var err error
	// We want to get all posts here for the merge, not just unread
	posts, err := user.GetPostsByName(feed.Folder, feed.Name, true)
	posts, err := user.GetAllPostsByFeed(feed)
	if err != nil {
		return err
	}


@@ 51,7 52,7 @@ func (user User) UpdateFeed(feed Feed) error {
		post := pluckPost(posts, webPost.UUID)
		if post == nil {
			// This item isn't in our database yet.
			err = user.AddPost(webPost)
			err := user.AddPost(webPost)
			// If we get an error here it's a database issue.
			// No sense to continue, kick it upwards
			if err != nil {

M main.go => main.go +5 -1
@@ 35,13 35,17 @@ func main() {
		panic(fmt.Errorf("Error opening database: %w", err))
	}

/*
	if *userFlag == "" {
		panic("Please specify a user")
	}
*/
	user, err := axolotl.GetUserByName(*userFlag)
/*
	if err != nil {
		panic(fmt.Errorf("User does not exist: %w", err))
	}
*/

	cmd := flag.Arg(0)
	switch cmd {


@@ 96,7 100,7 @@ func main() {
		if err != nil {
			panic(err)
		}
	default:
	case "serve":
		ServeTheWeb()
	}
}