Monorepo for Tangled
0

Configure Feed

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

appview: move tx into `UpsertProfile`

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

Seongmin Lee (Jun 30, 2026, 3:51 PM +0900) 928c2678 97396d80

+18 -54
+12 -2
appview/db/profile.go
··· 130 130 return years*12 + months 131 131 } 132 132 133 - func UpsertProfile(tx *sql.Tx, profile *models.Profile) error { 133 + func UpsertProfile(e *DB, profile *models.Profile) error { 134 + tx, err := e.Begin() 135 + if err != nil { 136 + return err 137 + } 138 + defer tx.Rollback() 139 + 134 140 // update links 135 - _, err := tx.Exec(`delete from profile_links where did = ?`, profile.Did) 141 + _, err = tx.Exec(`delete from profile_links where did = ?`, profile.Did) 136 142 if err != nil { 137 143 return err 138 144 } ··· 227 233 log.Println("profile_pinned_repositories", "err", err) 228 234 return err 229 235 } 236 + } 237 + 238 + if err := tx.Commit(); err != nil { 239 + return err 230 240 } 231 241 return nil 232 242 }
+2 -12
appview/ingester.go
··· 598 598 PreferredHandle: preferredHandle, 599 599 } 600 600 601 - tx, err := i.Db.Begin() 602 - if err != nil { 603 - return fmt.Errorf("failed to start transaction: %w", err) 604 - } 605 - defer tx.Rollback() 606 - 607 - err = db.ValidateProfile(tx, &profile) 601 + err = db.ValidateProfile(i.Db, &profile) 608 602 if err != nil { 609 603 return fmt.Errorf("invalid profile record") 610 604 } 611 605 612 - err = db.UpsertProfile(tx, &profile) 606 + err = db.UpsertProfile(i.Db, &profile) 613 607 if err != nil { 614 608 return fmt.Errorf("upserting profile: %w", err) 615 609 } 616 610 617 - err = tx.Commit() 618 - if err != nil { 619 - return fmt.Errorf("tx.Commit: %w", err) 620 - } 621 611 if i.Cache != nil { 622 612 pipe := i.Cache.Pipeline() 623 613 didKey := fmt.Sprintf(cache.PreferredHandleByDid, did)
+1 -7
appview/oauth/handler.go
··· 336 336 return 337 337 } 338 338 339 - tx, err := o.Db.BeginTx(ctx, nil) 340 - if err != nil { 341 - l.Error("failed to start transaction", "err", err) 342 - return 343 - } 344 - 345 339 emptyProfile := &models.Profile{Did: did} 346 - if err := db.UpsertProfile(tx, emptyProfile); err != nil { 340 + if err := db.UpsertProfile(o.Db, emptyProfile); err != nil { 347 341 l.Error("failed to create empty profile in DB", "err", err) 348 342 return 349 343 }
+3 -33
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 - } 901 887 902 888 client, err := s.oauth.AuthorizedClient(r) 903 889 if err != nil { ··· 952 938 return 953 939 } 954 940 955 - if err := tx.Commit(); err != nil { 941 + if err := db.UpsertProfile(s.db, profile); err != nil { 956 942 // db failed, but PDS operation succeed. 957 943 // log error and continue 958 944 l.Error("failed to update profile in DB", "err", err) ··· 1193 1179 } 1194 1180 profile.Avatar = uploadBlobResp.Blob.Ref.String() 1195 1181 1196 - tx, err := s.db.BeginTx(r.Context(), nil) 1197 - if err != nil { 1198 - l.Error("failed to start transaction", "err", err) 1199 - s.pages.HxRefresh(w) 1200 - w.WriteHeader(http.StatusOK) 1201 - return 1202 - } 1203 - 1204 - err = db.UpsertProfile(tx, profile) 1182 + err = db.UpsertProfile(s.db, profile) 1205 1183 if err != nil { 1206 1184 l.Error("failed to update profile in DB", "err", err) 1207 1185 s.pages.HxRefresh(w) ··· 1271 1249 } 1272 1250 profile.Avatar = "" 1273 1251 1274 - tx, err := s.db.BeginTx(r.Context(), nil) 1275 - if err != nil { 1276 - l.Error("failed to start transaction", "err", err) 1277 - s.pages.HxRefresh(w) 1278 - w.WriteHeader(http.StatusOK) 1279 - return 1280 - } 1281 - 1282 - err = db.UpsertProfile(tx, profile) 1252 + err = db.UpsertProfile(s.db, profile) 1283 1253 if err != nil { 1284 1254 l.Error("failed to update profile in DB", "err", err) 1285 1255 s.pages.HxRefresh(w)