Fixed bug where tags were not being recorded correctly.

This commit is contained in:
Nick Gerakines 2020-03-14 14:16:00 -04:00
parent 04fd776cee
commit dc2afcdecd
No known key found for this signature in database
GPG Key ID: 33D43D854F96B2E4
3 changed files with 17 additions and 3 deletions

View File

@ -19,6 +19,7 @@ type ObjectStorage interface {
ListObjectEventPayloadsInFeed(ctx context.Context, userID uuid.UUID, limit int, offset int) ([]Payload, error)
CountObjectPayloadsInLocalFeed(ctx context.Context) (int, error)
ListObjectPayloadsInLocalFeed(ctx context.Context) ([]Payload, error)
CountObjectPayloadsInTagFeed(ctx context.Context, tag string) (int, error)
ListObjectPayloadsInTagFeed(ctx context.Context, tag string) ([]Payload, error)
CountObjectPayloadsInUserOutbox(ctx context.Context, userID uuid.UUID) (int, error)
ListObjectPayloadsInUserOutbox(ctx context.Context, userID uuid.UUID, limit int, offset int) ([]Payload, error)
@ -84,6 +85,11 @@ func (s pgStorage) ListObjectPayloadsInLocalFeed(ctx context.Context) ([]Payload
return s.objectPayloads(ctx, query)
}
func (s pgStorage) CountObjectPayloadsInTagFeed(ctx context.Context, tag string) (int, error) {
query := `SELECT COUNT(o.payload) FROM user_object_events uoe INNER JOIN object_events oe on oe.id = uoe.activity_id INNER JOIN objects o on oe.object_id = o.id INNER JOIN object_tags ot on ot.object_id = o.id WHERE uoe.public = true AND ot.tag = $1`
return s.RowCount(ctx, query, tag)
}
func (s pgStorage) ListObjectPayloadsInTagFeed(ctx context.Context, tag string) ([]Payload, error) {
query := `SELECT o.payload FROM user_object_events uoe INNER JOIN object_events oe on oe.id = uoe.activity_id INNER JOIN objects o on oe.object_id = o.id INNER JOIN object_tags ot on ot.object_id = o.id WHERE uoe.public = true AND ot.tag = $1`
return s.objectPayloads(ctx, query, tag)

View File

@ -224,7 +224,8 @@ func (h handler) createNote(c *gin.Context) {
language: content,
}
}
note["context"] = conversation
// The spec is really vague about how note context can be used.
// note["context"] = conversation
note["conversation"] = conversation
noteURL := fmt.Sprintf("https://%s/object/%s", h.domain, createNoteID)
note["id"] = noteURL
@ -301,7 +302,7 @@ func (h handler) createNote(c *gin.Context) {
"href": fmt.Sprintf("https://%s/tags/%s", h.domain, clean),
"name": hashtag,
})
if len(firstTags) < 5 {
if len(firstTags) < 10 {
firstTags = append(firstTags, clean)
}
}
@ -385,6 +386,13 @@ func (h handler) createNote(c *gin.Context) {
return err
}
for _, tag := range firstTags {
_, err = storage.RecordObjectTag(ctx, activityObjectRowID, tag)
if err != nil {
return err
}
}
return nil
})
if err != nil {

View File

@ -23,7 +23,7 @@ func (h handler) getTaggedObjects(c *gin.Context) {
page := intParam(c, "page", 0)
limit := 50
total, err := h.storage.RowCount(ctx, `SELECT COUNT(*) FROM user_activities WHERE public = TRUE AND tags @> ARRAY[$1]::varchar[]`, tag)
total, err := h.storage.CountObjectPayloadsInTagFeed(ctx, tag)
if err != nil {
h.internalServerErrorJSON(c, err)
return