Monorepo for Tangled tangled.org
5

Configure Feed

Select the types of activity you want to include in your feed.

appview: move tx rollback logic out of `db.UpsertProfile()`

Signed-off-by: Seongmin Lee <git@boltless.me>

author
Seongmin Lee
date (Jun 25, 2026, 2:51 AM +0900) commit 966b455b parent 4fdeaa00 change-id uulpoknx
+28 -15
+1 -4
appview/db/profile.go
··· 131 131 } 132 132 133 133 func UpsertProfile(tx *sql.Tx, profile *models.Profile) error { 134 - defer tx.Rollback() 135 - 136 134 // update links 137 135 _, err := tx.Exec(`delete from profile_links where did = ?`, profile.Did) 138 136 if err != nil { ··· 230 228 return err 231 229 } 232 230 } 233 - 234 - return tx.Commit() 231 + return nil 235 232 } 236 233 237 234 func DeleteProfile(tx *sql.Tx, did string) error {
+10 -1
appview/ingester.go
··· 596 596 if err != nil { 597 597 return fmt.Errorf("failed to start transaction: %w", err) 598 598 } 599 + defer tx.Rollback() 599 600 600 601 err = db.ValidateProfile(tx, &profile) 601 602 if err != nil { ··· 603 604 } 604 605 605 606 err = db.UpsertProfile(tx, &profile) 606 - if err == nil && i.Cache != nil { 607 + if err != nil { 608 + return fmt.Errorf("upserting profile: %w", err) 609 + } 610 + 611 + err = tx.Commit() 612 + if err != nil { 613 + return fmt.Errorf("tx.Commit: %w", err) 614 + } 615 + if i.Cache != nil { 607 616 pipe := i.Cache.Pipeline() 608 617 didKey := fmt.Sprintf(cache.PreferredHandleByDid, did) 609 618 if preferredHandle != "" {
+17 -10
appview/state/profile.go
··· 884 884 func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r *http.Request) { 885 885 l := s.logger.With("handler", "updateProfile") 886 886 user := s.oauth.GetMultiAccountUser(r) 887 + tx, err := s.db.BeginTx(r.Context(), nil) 888 + if err != nil { 889 + l.Error("failed to start transaction", "err", err) 890 + s.pages.Notice(w, "update-profile", "Failed to update profile, try again later.") 891 + return 892 + } 893 + defer tx.Rollback() 894 + 895 + err = db.UpsertProfile(tx, profile) 896 + if err != nil { 897 + l.Error("failed to update profile", "err", err) 898 + s.pages.Notice(w, "update-profile", "Failed to update profile, try again later.") 899 + return 900 + } 887 901 888 902 client, err := s.oauth.AuthorizedClient(r) 889 903 if err != nil { ··· 938 952 return 939 953 } 940 954 941 - tx, err := s.db.BeginTx(r.Context(), nil) 942 - if err != nil { 943 - l.Error("failed to start transaction", "err", err) 944 - s.pages.Notice(w, "update-profile", "Failed to update profile, try again later.") 945 - return 946 - } 947 - 948 - if err := db.UpsertProfile(tx, profile); err != nil { 955 + if err := tx.Commit(); err != nil { 956 + // db failed, but PDS operation succeed. 957 + // log error and continue 949 958 l.Error("failed to update profile in DB", "err", err) 950 - s.pages.Notice(w, "update-profile", "Failed to update profile, try again later.") 951 - return 952 959 } 953 960 954 961 if s.rdb != nil {