Page MenuHomePhorge

Add getQueryApplicationClass() to *TransactionQuery.php classes
ClosedPublic

Authored by aklapper on Dec 25 2023, 20:29.

Details

Summary

Add getQueryApplicationClass() to all *TransactionQuery.php classes similar to other *Query.php classes having the same function, and make the parent function in PhabricatorApplicationTransactionQuery.php abstract.

In the future, this will enable excluding transaction query results based on their underlying application (for example if an application has been uninstalled) to mitigate the problem of overheated search results. See https://we.phorge.it/T15642 for context.

The only callers of getQueryApplicationClass() are in src/infrastructure/query/policy/PhabricatorPolicyAwareQuery.php and src/applications/policy/__tests__/PhabricatorPolicyTestCase.php.

See T15642

Test Plan

Patch changes only one existing code place, thus check if related pages still work as expected:

Diff Detail

Repository
rP Phorge
Branch
T15642transactionQueryClassesAppName (branched from master)
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 994
Build 994: arc lint + arc unit

Event Timeline

src/applications/meta/query/PhabricatorApplicationApplicationTransactionQuery.php
11

Must return null otherwise pages like http://phorge.localhost/applications/view/PhabricatorSomethingApplication/ will raise an exception No application 'Foo'!.

Document abstract function that it can return string|null

Thanks! some quick tips maybe relevant:

  1. Maybe we can return ClassName::class - that is supported since PHP 5.5
    • among other things, the ::class also better integrates with an IDE to find class usages
    • I see that ::class is already in-use in Phorge here and there
  2. I've seen the comment https://we.phorge.it/D25500#inline-3509. If I understand correctly, we changed PhabricatorApplicationTransactionQuery#getQueryApplicationClass() so, the IDE helped to find classes to touch. Since we already done that, maybe better to restore, so we can omit methods that just return null
src/infrastructure/daemon/workers/query/PhabricatorWorkerBulkJobTransactionQuery.php
11

Example change

lgtm

Thanks. Don't take my comments seriously. Probably they have no sense.

This revision is now accepted and ready to land.Jan 8 2024, 13:24

Revert turning getQueryApplicationClass() abstract in the parent class src/applications/transactions/query/PhabricatorApplicationTransactionQuery.php and make it return null again (and thus remove the only newly added call which returned null in src/applications/meta/query/PhabricatorApplicationApplicationTransactionQuery.php); also return ::class as proposed by Valerio

Maybe we can return ClassName::class - that is supported since PHP 5.5

Note to myself: Makes sense; there's a lot more code to update in random *Query.php classes defining getQueryApplicationClass() functions, in a separate future patch

Maybe we can return ClassName::class - that is supported since PHP 5.5

there's a lot more code to update in random *Query.php classes defining getQueryApplicationClass() functions, in a separate future patch

Done in D25524

and thus remove the only newly added call which returned null in src/applications/meta/query/PhabricatorApplicationApplicationTransactionQuery.php)

Put that one file back in, as it's clearer to explicitly make that one case return null. See https://we.phorge.it/source/phorge/browse/master/src/applications/meta/query/PhabricatorApplicationQuery.php$165 whose explanation I copied.