-
-
Notifications
You must be signed in to change notification settings - Fork 839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search Filter Split, Use Same Controller #2454
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arguments for the controller construct should be similar. In the DiscussionController the repository is the first argument, in the UsersController it's the last.
Great job!
Aside from that I see nothing wrong with this. How this impacts extensions is still a bit unclear and I think seeing it in action will give more insight in whether this is the best approach or not.
We generally stick to alphabetical order for constructor arguments, I think that's something worth sticking to. One thing I'm considering is:
That would make the API for filtering much more similar to the API for searching, but isn't strictly necessary. Any thoughts @flarum/core @SychO9? |
71c90b3
to
07fbdb1
Compare
07fbdb1
to
46674fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any issues with using a single endpoint, I think it'll work just fine.
I'm leaning towards having a single class implementing both the gambit and the filter interfaces, even if we don't reduce code duplication, having them in one place would be better I think.
That would make the API for filtering much more similar to the API for searching, but isn't strictly necessary. Any thoughts
I would be in favour. It's more consistent with the search API, but also cleaner imho. Although having a filterer for each resource would mean more duplicated code similarly to resource searchers 🤔
src/Filter/Filterer.php
Outdated
$this->applyOffset($wrappedFilter, $offset); | ||
$this->applyLimit($wrappedFilter, $limit + 1); | ||
|
||
foreach (Arr::get(static::$filterMutators, $resource, []) as $mutator) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we dispatch a filtering event before this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there such a thing? Do you mean Searching
? Not including it would be a breaking change, but we don't have an instance of AbstractSearch
or SearchCriteria
to include.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah true, nvm then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@SychO9 hey, guess what, we now have an instance of AbstractSearch
and SearchCriteria
to include! Yay!!!
That being said, we don't have a list of applied gambits, so it's a partial BC patch if any. Since any extensions that use Searching or add gambits will almost definitely need to be updated anyways, I'm not sure if it's worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I thought about that, I also don't think that we need to do that, we're good as is imho.
Any thoughts on where to house these? At one point I was thinking of setting up a |
I'll leave this alone for now and work on the filter/gambit combo. If we were to make a |
Yea that's the problem, I'd be fine with it under Filter (filters implementing the gambit interface), not sure about the other devs though. |
173056b
to
583ed0d
Compare
I've taken some time to think about this, and I'm now 99% sure we need to have per-resource filterers that get passed a |
30a06c2
to
ca5ffcc
Compare
I've reimplemented Filterer to be abstract and have per-resource classes like with searchers, and looking over the code again, I think this was the right move. As a followup, there are several "abstraction" classes used by both filterers and searchers (SearchCriteria/FIlterCriteria, SearchResults, AbstractSearch/WrappedFilter). I think we could get away with combining these into a shared class (QueryCriteria, QueryResults, AbstractQuery (this one is challenging since AbstractSearch keeps track of applied gambits)). Only problem is, where should these be located in the code? Maybe a One big benefit of having a common signature to the |
if (! $search instanceof DiscussionSearch) { | ||
throw new LogicException('This gambit can only be applied on a DiscussionSearch'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we dropping these ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure it's that useful. Core's gambits aren't really used outside of core, so little risk of them being applied to the wrong search. And removing it here doesn't really affect external gambits, although with those, now that gambits are registered directly (and not via an event) it's much less likely to attach a gambit to the wrong searcher.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, doesn't hurt to have it though. Looking at the code, it seems to have been there because we can't explicitly typehint the conditions method with the exact search class, because the method signature has to be identical to the parent class's abstract method. And this bit of code also helps IDEs like phpStorm know the specific type of the $search object, which isn't really much useful at the moment considering these classes don't have anything more than their abstract parent (DiscussionSearch does have additional methods but none of them seem to be used anywhere).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's fair. In that case, should WrappedFilter
be redesigned as AbstractFilter
, so we can have a similar system for filtering? I'm not sure it'd be that useful, since you wouldn't really have "relevant posts" when filtering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I'm all for consistency, I also don't really see it being of use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For that matter, do we have a use case for separate "search" classes for each model? As you noted, the specialized methods/fields on the DiscussionSearch one aren't used, and extensions can't add new methods onto it, so there's no use there. Furthermore, if we made AbstractSearch non-abstract and just used that, it wouldn't block us from switching back to subclass of it eventually, since polymorphism. But if we were to get rid of it, that'd be yet another reason to switch to WrappedQuery
for both filter and search, and WrappedSearch
for search, which would keep track of applied gambits. Although preferably with better naming 😆
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed! That really seems to be the case, just need to make 100% sure those methods are not used, and then we could in a separate pull request look into the Query
namespace (just to avoid more drastic changes in this PR so that other devs can review more easily).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, never mind: DiscussionSearch
has a $defaultSort
field. And THAT could be applicable to filters too. Urgh....
I'll think some more about this, but I think we're nearing completion for this refactor other than this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
New proposal: https://github.com/flarum/core/issues/1355
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
[ci skip] [skip ci]
This is already done in the searcher
$load is the mechanism, $include is the actual important bit.
On second thought, the searcher / filterer shouldn't be responsible for loading related items. It centralizes code, but isn't proper (and breaks `Discussion::setStateUser()`)
[ci skip] [skip ci]
fe469ff
to
97ac81a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have not tested locally, but it looks good code wise as far as I can tell
Start of flarum/issue-archive#286
Supercedes #2453
Changes proposed in this pull request:
TODO:
Reviewers should focus on: