Page MenuHomePhabricator

Remove flags and tokens upon object destruction
ClosedPublic

Authored by joshuaspence on Jun 2 2015, 12:02 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Dec 14, 5:57 AM
Unknown Object (File)
Tue, Dec 10, 8:43 PM
Unknown Object (File)
Tue, Dec 10, 6:29 PM
Unknown Object (File)
Sun, Dec 8, 4:34 AM
Unknown Object (File)
Tue, Nov 26, 9:17 PM
Unknown Object (File)
Thu, Nov 21, 1:18 PM
Unknown Object (File)
Wed, Nov 20, 1:24 AM
Unknown Object (File)
Nov 16 2024, 9:58 AM
Subscribers

Details

Reviewers
epriestley
Group Reviewers
Blessed Reviewers
Commits
Restricted Diffusion Commit
rP0b87e462cd70: Remove flags and tokens upon object destruction
Summary

When destroying an object, also remove all associated flags and tokens.

Test Plan

Awarded a Maniphest task with a token and flagged it as well. Destroyed it with ./bin/remove destroy and saw flag and token removed from the database.

Diff Detail

Repository
rP Phabricator
Branch
master
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 6449
Build 6471: [Placeholder Plan] Wait for 30 Seconds

Event Timeline

joshuaspence retitled this revision from to Remove flags and tokens upon object destruction.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
epriestley edited edge metadata.
This revision is now accepted and ready to land.Jun 2 2015, 12:02 PM

One thing I think we don't handle is if a user is being deleted, we won't nuke the flags/tokens of that user.

It's probably correct not to remove tokens they gave.

We could remove their flags.

src/applications/system/engine/PhabricatorDestructionEngine.php
82

Is there any reason to use PhabricatorTokenGivenQuery here?

src/applications/system/engine/PhabricatorDestructionEngine.php
82

There's an argument against using it: some types of Queries require related objects to exist, even if querying with the Omnipotent viewer.

For example, TransactionQuery classes refuse to load transactions if the objects aren't loadable, even if the rows exist. The general idea is that the overwhelming majority of application code is way simpler if it doesn't need to check that every object is complete/valid, and we normally can't policy check these objects anyway.

In this case we need to load those "broken/invalid" rows, so destroyTransactions() queries the database directly instead of using an appropriate Query class.

It looks like TokenGivenQuery has similar logic, and refuses to load tokens if the objects don't load, so I would expect it to never "see" any tokens (since we just destroyed their objects).

There are at least two reasons why this might be bad:

  • $token->delete() might expect that the token is in some state that only Query puts it in. I don't think it does today, but, for example, CalendarEvent has some special postprocessing in the Query and loading an object via the Query vs via load() can give you objects in meaningfully different states.
  • If there are a million results, we should ideally iterate over them in pages, not bulk-load them all at once (e.g., deleting an object with 1M tokens might exhaust RAM or something right now). I suppose that in this specific case, since we're deleting the rows, we could just issue the same query over and over again with a LIMIT until it comes back empty, although that's a little sketchy. In the general case, if we wanted to build a "query iterator with constraints", it might make more sense to put it on Query than on the raw DAO. But maybe not. Maybe just letting LiskMigrationIterator add a condition to the WHERE clause would be good enough.
src/applications/system/engine/PhabricatorDestructionEngine.php
82

In the case of a large result set, probably it would be better to just use queryfx to DELETE FROM %T WHERE objectPHID = %s?

src/applications/system/engine/PhabricatorDestructionEngine.php
82

Yeah, but only if we're certain delete() has no other logic and that we'll definitely remember to fix this if it ever does. In the general case, some delete() methods do something.

joshuaspence edited edge metadata.

Remove user flags

This revision was automatically updated to reflect the committed changes.