WIP: Add: Trending Algo (Score) (Kind 20) #2
@ -8,22 +8,12 @@ import (
|
||||
"git.highperfocused.tech/highperfocused/lumina-relay/relay/cache"
|
||||
)
|
||||
|
||||
type Post struct {
|
||||
ID string `json:"id"`
|
||||
PubKey string `json:"pubkey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Kind string `json:"kind"`
|
||||
Content string `json:"content"`
|
||||
Tags [][]string `json:"tags"`
|
||||
ReactionCount int `json:"reaction_count"`
|
||||
}
|
||||
|
||||
var (
|
||||
trendingCache = cache.New()
|
||||
cacheDuration = 5 * time.Minute
|
||||
)
|
||||
|
||||
// GetTrendingKind20 returns the top 20 trending posts of kind 20 from the last 24 hours
|
||||
// GetTrendingBasicKind20 returns the top 20 trending posts of kind 20 from the last 24 hours
|
||||
func GetTrendingBasicKind20(db *sql.DB) ([]Post, error) {
|
||||
if cached, ok := trendingCache.Get("trending_kind_20"); ok {
|
||||
return cached.([]Post), nil
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
// GetTrendingKind20 returns the top 20 trending posts of kind 20 from the last 24 hours
|
||||
// GetTrendingScoreKind20 returns the top 20 trending posts of kind 20 from the last 24 hours
|
||||
func GetTrendingScoreKind20(db *sql.DB) ([]Post, error) {
|
||||
if cached, ok := trendingCache.Get("trending_kind_20"); ok {
|
||||
return cached.([]Post), nil
|
||||
@ -45,7 +45,7 @@ func GetTrendingScoreKind20(db *sql.DB) ([]Post, error) {
|
||||
e.kind,
|
||||
e.content,
|
||||
e.tags,
|
||||
COALESCE(s.trending_score, 0) as reaction_count
|
||||
COALESCE(s.trending_score, 0.0) as reaction_count -- Cast to float
|
||||
FROM event e
|
||||
LEFT JOIN scores s ON e.id = s.original_event_id
|
||||
WHERE e.kind::text = '20'
|
||||
|
13
relay/trending/types.go
Normal file
13
relay/trending/types.go
Normal file
@ -0,0 +1,13 @@
|
||||
package trending
|
||||
|
||||
import "time"
|
||||
|
||||
type Post struct {
|
||||
ID string `json:"id"`
|
||||
PubKey string `json:"pubkey"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
Kind int `json:"kind"`
|
||||
Content string `json:"content"`
|
||||
Tags [][]string `json:"tags"`
|
||||
ReactionCount float64 `json:"reaction_count"`
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user