Monorepo for Tangled tangled.org

appview/db: fix stray stars from deleted repositories #1129

closed opened by melois.dev targeting master from melois.dev/tangled.org-core: youn/push-wurmoyttrvoy

Fixes https://tangled.org/tangled.org/core/issues/433.

This PR includes two migrations :

  • A trigger on the repos table to delete associated stars when a repo is removed, restoring the previous cascading behavior.
  • A one-time cleanup to purge orphaned stars.
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:sl3qsialnnm24haayxlidcwu/sh.tangled.repo.pull/3mgnyinjqkr22
+24
Diff #0
+24
appview/db/db.go
··· 1255 1255 return err 1256 1256 }) 1257 1257 1258 + // the generalize-stars-subject migration removed the foreign key constraint 1259 + // from stars, so deleting a repo no longer cascades to its stars. 1260 + // this trigger restores that behaviour at the application level. 1261 + orm.RunMigration(conn, logger, "add-star-cleanup-trigger", func(tx *sql.Tx) error { 1262 + _, err := tx.Exec(` 1263 + create trigger if not exists delete_stars_on_repo_delete 1264 + after delete on repos 1265 + begin 1266 + delete from stars where subject_at = OLD.at_uri; 1267 + end; 1268 + `) 1269 + return err 1270 + }) 1271 + 1272 + // purge stars that reference repos deleted before the trigger was added. 1273 + orm.RunMigration(conn, logger, "cleanup-orphaned-stars", func(tx *sql.Tx) error { 1274 + _, err := tx.Exec(` 1275 + delete from stars 1276 + where subject_at like 'at://%/sh.tangled.repo/%' 1277 + and subject_at not in (select at_uri from repos); 1278 + `) 1279 + return err 1280 + }) 1281 + 1258 1282 return &DB{ 1259 1283 db, 1260 1284 logger,

History

1 round 3 comments
sign up or login to add to the discussion
melois.dev submitted #0
1 commit
expand
appview/db: fix stray stars from deleted repositories
expand 3 comments

I removed the cascading behavior on purpose. Because repo and star are stored in different PDSs, repo deletion doesn't directly mean star deletion (same goes to issues/prs). We can hide the orphaned stars on view, but ideally the db record lifecycle should follow the PDS record lifecycle imo.

Alright, I'm still new to this ATP ecosystem I did not catch this intent, thank you for the clarification.

So what you mean instead is to filter out the orphaned stars in db.CountStars and db.GetVanityStat (in the case models.VanityStatStarCount) ?

Yes! or maybe creating a dedicated sqlite view table for filtered out stars.

closed without merging