Skip to content

Commit

Permalink
Improve friend parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Jim Yeh committed Mar 20, 2020
1 parent 39bd962 commit a1b024c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
26 changes: 21 additions & 5 deletions background/parser/facebook.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"time"

"github.com/aws/aws-sdk-go/aws/session"
"github.com/getsentry/sentry-go"
Expand Down Expand Up @@ -186,18 +187,33 @@ func ParseFacebookArchive(sess *session.Session, db *gorm.DB, accountNumber, wor
friendIDs[f.FriendName] = f.ID
}

// FIXME: non-friends couldn't be tagged
for _, tag := range postTags {
friendID, ok := friendIDs[tag.FriendName]
if ok {
tag.FriendID = friendID
tag.PostID = p.ID
if err := db.Create(&tag).Error; err != nil {
if !ok {
friend := &facebook.FriendORM{
FriendName: tag.FriendName,
DataOwnerID: dataOwner,
Timestamp: time.Now().UnixNano(),
}
if err := db.Where("data_owner_id = ? AND friend_name = ?", dataOwner, tag.FriendName).
FirstOrCreate(&friend).Error; err != nil {
if err != sql.ErrNoRows {
contextLogger.Error(err)
sentry.CaptureException(err)
continue
}
}

friendID = friend.ID
friendIDs[tag.FriendName] = friendID
}
tag.FriendID = friendID
tag.PostID = p.ID
if err := db.Create(&tag).Error; err != nil {
if err != sql.ErrNoRows {
contextLogger.Error(err)
sentry.CaptureException(err)
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion schema/facebook/friend.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ func FriendSchemaLoader() *gojsonschema.Schema {

type FriendORM struct {
ID uuid.UUID `gorm:"type:uuid;primary_key" sql:"default:uuid_generate_v4()"`
FriendID int64
FriendName string
Timestamp int64 `gorm:"unique_index:facebook_friend_owner_timestamp_unique"`
DataOwnerID string `gorm:"unique_index:facebook_friend_owner_timestamp_unique"`
Expand Down

0 comments on commit a1b024c

Please sign in to comment.