fix: Fix database query
Fix ordering in database query if more than one tweet with same timestamp
This commit is contained in:
parent
711f2d2e7b
commit
712d83c0f0
1 changed files with 4 additions and 4 deletions
|
@ -57,7 +57,7 @@ func NewDatabase(driver string, connectString string) (*Database, error) {
|
||||||
|
|
||||||
func (db *Database) GetNewestTweet(channel string) (*Tweet, error) {
|
func (db *Database) GetNewestTweet(channel string) (*Tweet, error) {
|
||||||
tweet := Tweet{}
|
tweet := Tweet{}
|
||||||
err := db.Get(&tweet, "SELECT * FROM tweet WHERE channel=$1 ORDER BY timestamp DESC LIMIT 1", channel)
|
err := db.Get(&tweet, "SELECT * FROM tweet WHERE channel=$1 ORDER BY timestamp DESC, snowflake DESC LIMIT 1", channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ func (db *Database) GetNewestTweet(channel string) (*Tweet, error) {
|
||||||
|
|
||||||
func (db *Database) GetTweets(channel string) ([]*Tweet, error) {
|
func (db *Database) GetTweets(channel string) ([]*Tweet, error) {
|
||||||
tweet := []*Tweet{}
|
tweet := []*Tweet{}
|
||||||
err := db.Select(&tweet, "SELECT * FROM tweet WHERE channel=$1 ORDER BY timestamp DESC", channel)
|
err := db.Select(&tweet, "SELECT * FROM tweet WHERE channel=$1 ORDER BY timestamp DESC, snowflake DESC", channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func (db *Database) ContainsTweet(channel string, tweet *ts.Tweet) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
t := Tweet{}
|
t := Tweet{}
|
||||||
rows, err := db.Queryx("SELECT * FROM tweet WHERE channel=$1 ORDER BY timestamp DESC", channel)
|
rows, err := db.Queryx("SELECT * FROM tweet WHERE channel=$1 ORDER BY timestamp DESC, snowflake DESC", channel)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func (db *Database) PruneOldestTweets(channel string) error {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rows, err := tx.Queryx("SELECT tweet_id from tweet WHERE channel=$1 ORDER by timestamp ASC LIMIT $2", channel, count-KeepTweets)
|
rows, err := tx.Queryx("SELECT tweet_id from tweet WHERE channel=$1 ORDER by timestamp ASC, snowflake ASC LIMIT $2", channel, count-KeepTweets)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue