chore: refactor
This commit is contained in:
51
feed.go
51
feed.go
@@ -21,13 +21,14 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.sour.is/xt/internal/otel"
|
||||
"go.sour.is/xt/internal/uuid"
|
||||
"go.yarn.social/lextwt"
|
||||
"go.yarn.social/types"
|
||||
)
|
||||
|
||||
type Feed struct {
|
||||
FeedID uuid
|
||||
ParentID uuid
|
||||
FeedID uuid.UUID
|
||||
ParentID uuid.UUID
|
||||
HashURI string
|
||||
URI string
|
||||
Nick string
|
||||
@@ -236,7 +237,7 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
|
||||
loadTS := time.Now()
|
||||
refreshRate := 600
|
||||
|
||||
feedID := urlNS.UUID5(cmp.Or(f.Twter().HashingURI, f.Twter().URI))
|
||||
feedID := uuid.UrlNS.UUID5(cmp.Or(f.Twter().HashingURI, f.Twter().URI))
|
||||
|
||||
tx, err := db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
@@ -269,13 +270,13 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
|
||||
for _, twt := range twts {
|
||||
twtID := makeULID(twt)
|
||||
|
||||
mentions := make(uuids, 0, len(twt.Mentions()))
|
||||
mentions := make(uuid.UUIDs, 0, len(twt.Mentions()))
|
||||
for _, mention := range twt.Mentions() {
|
||||
followMap[mention.Twter().URI] = mention.Twter().Nick
|
||||
mentions = append(mentions, urlNS.UUID5(mention.Twter().URI))
|
||||
mentions = append(mentions, uuid.UrlNS.UUID5(mention.Twter().URI))
|
||||
}
|
||||
|
||||
tags := make(strList, 0, len(twt.Tags()))
|
||||
tags := make(uuid.List, 0, len(twt.Tags()))
|
||||
for _, tag := range twt.Tags() {
|
||||
tags = append(tags, tag.Text())
|
||||
}
|
||||
@@ -335,7 +336,7 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
|
||||
}
|
||||
|
||||
part = uri[:strings.LastIndex(uri, "/")+1] + part
|
||||
childID := urlNS.UUID5(part)
|
||||
childID := uuid.UrlNS.UUID5(part)
|
||||
fmt.Println("found prev", uri, part)
|
||||
args = append(args,
|
||||
childID, // feed_id
|
||||
@@ -351,13 +352,13 @@ func storeFeed(ctx context.Context, db db, f types.TwtFile) error {
|
||||
|
||||
for uri, nick := range followMap {
|
||||
args = append(args,
|
||||
urlNS.UUID5(uri), // feed_id
|
||||
nil, // parent_id
|
||||
nick, // nick
|
||||
uri, // uri
|
||||
"warm", // state
|
||||
nil, // last_scan_on
|
||||
refreshRate, // refresh_rate
|
||||
uuid.UrlNS.UUID5(uri), // feed_id
|
||||
nil, // parent_id
|
||||
nick, // nick
|
||||
uri, // uri
|
||||
"warm", // state
|
||||
nil, // last_scan_on
|
||||
refreshRate, // refresh_rate
|
||||
)
|
||||
}
|
||||
for query, args := range chunk(args, insertFeed, db.MaxVariableNumber) {
|
||||
@@ -389,7 +390,7 @@ func storeRegistry(ctx context.Context, db db, in io.Reader) error {
|
||||
|
||||
nick := twt.Twter().DomainNick()
|
||||
uri := twt.Twter().URI
|
||||
feedID := urlNS.UUID5(uri)
|
||||
feedID := uuid.UrlNS.UUID5(uri)
|
||||
twtID := makeULID(twt)
|
||||
text := fmt.Sprintf("%+l", twt)
|
||||
|
||||
@@ -405,13 +406,13 @@ func storeRegistry(ctx context.Context, db db, in io.Reader) error {
|
||||
|
||||
twters[uri] = nick
|
||||
|
||||
mentions := make(uuids, 0, len(twt.Mentions()))
|
||||
mentions := make(uuid.UUIDs, 0, len(twt.Mentions()))
|
||||
for _, mention := range twt.Mentions() {
|
||||
twters[uri] = nick
|
||||
mentions = append(mentions, urlNS.UUID5(mention.Twter().URI))
|
||||
mentions = append(mentions, uuid.UrlNS.UUID5(mention.Twter().URI))
|
||||
}
|
||||
|
||||
tags := make(strList, 0, len(twt.Tags()))
|
||||
tags := make(uuid.List, 0, len(twt.Tags()))
|
||||
for _, tag := range twt.Tags() {
|
||||
tags = append(tags, tag.Text())
|
||||
}
|
||||
@@ -466,7 +467,7 @@ func storeRegistry(ctx context.Context, db db, in io.Reader) error {
|
||||
// continue
|
||||
// }
|
||||
|
||||
feedID := urlNS.UUID5(uri)
|
||||
feedID := uuid.UrlNS.UUID5(uri)
|
||||
|
||||
args = append(args,
|
||||
feedID, // feed_id
|
||||
@@ -641,7 +642,7 @@ func fetchTwts(ctx context.Context, db db, uri string, limit int, offset int64)
|
||||
where := `where feed_id in (select feed_id from feeds where state != 'permanantly-dead')`
|
||||
|
||||
if uri != "" {
|
||||
feed_id := urlNS.UUID5(uri)
|
||||
feed_id := uuid.UrlNS.UUID5(uri)
|
||||
where = "where feed_id = ?"
|
||||
args = append(args, feed_id)
|
||||
}
|
||||
@@ -732,7 +733,7 @@ func fetchUsers(ctx context.Context, db db, uri, q string) ([]types.Twt, error)
|
||||
args := make([]any, 0)
|
||||
if uri != "" {
|
||||
where = `where feed_id = ? or parent_id = ?`
|
||||
feed_id := urlNS.UUID5(uri)
|
||||
feed_id := uuid.UrlNS.UUID5(uri)
|
||||
args = append(args, feed_id, feed_id)
|
||||
} else if q != "" {
|
||||
where = `where nick like ?`
|
||||
@@ -783,7 +784,7 @@ func fetchUsers(ctx context.Context, db db, uri, q string) ([]types.Twt, error)
|
||||
return twts, nil
|
||||
}
|
||||
|
||||
func fetchMentions(ctx context.Context, db db, mention uuid, limit int, offset int64) ([]types.Twt, int64, int64, error) {
|
||||
func fetchMentions(ctx context.Context, db db, mention uuid.UUID, limit int, offset int64) ([]types.Twt, int64, int64, error) {
|
||||
ctx, span := otel.Span(ctx)
|
||||
defer span.End()
|
||||
|
||||
@@ -871,7 +872,7 @@ func fetchMentions(ctx context.Context, db db, mention uuid, limit int, offset i
|
||||
return twts, offset, end, err
|
||||
}
|
||||
|
||||
func fetchConv(ctx context.Context, db db, hash string, limit int, offset int64) ([]types.Twt, int64, int64, error) {
|
||||
func fetchConv(ctx context.Context, db db, hash string, _ int, offset int64) ([]types.Twt, int64, int64, error) {
|
||||
ctx, span := otel.Span(ctx)
|
||||
defer span.End()
|
||||
|
||||
@@ -925,7 +926,7 @@ func fetchConv(ctx context.Context, db db, hash string, limit int, offset int64)
|
||||
err = rows.Scan(&o.FeedID, &o.Hash, &o.Conv, &o.Nick, &o.URI, &o.Text)
|
||||
if err != nil {
|
||||
span.RecordError(err)
|
||||
return nil, 0,0,err
|
||||
return nil, 0, 0, err
|
||||
}
|
||||
twter := types.NewTwter(o.Nick, o.URI)
|
||||
twt, _ := lextwt.ParseLine(o.Text, &twter)
|
||||
@@ -934,4 +935,4 @@ func fetchConv(ctx context.Context, db db, hash string, limit int, offset int64)
|
||||
err = rows.Err()
|
||||
|
||||
return twts, offset, end, err
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user