Skip to content
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

ThemeQueryManager: Implement receive() #10014

Merged
merged 4 commits into from
Dec 13, 2016

Conversation

ockham
Copy link
Contributor

@ockham ockham commented Dec 13, 2016

Instead of just relying on that of the base class and implementing
matches() and sort() to make use of it.
This is because our themes query REST API endpoint uses ElasticSearch
heavily to sort results by relevancy. Mimicking ES's complex weighting
algorithms on the client side would be non-trivial, or would require a
heavy (and possibly slow) dependency such as elasticlunr.
By implementing receive() ourselves instead, we can override the base class
QueryManager's sorting behavior and keep the order as returned from the endpoint.

Also, move isThemeMatchingQuery() to state/themes/util since it's no longer needed by ThemeQueryManager (Ironically, this moving around of code makes up the largest part of the PR.)

To test: Check that theme sheets and the Current Theme bar still work. These are the only two places that already use ThemeQueryManager.

@ockham ockham added [Feature Group] Appearance & Themes Features related to the appearance of sites. [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Dec 13, 2016
@ockham ockham added this to the Themes: JetPress Rally milestone Dec 13, 2016
@ockham ockham self-assigned this Dec 13, 2016
@ockham ockham requested a review from seear December 13, 2016 19:18
@matticbot
Copy link
Contributor

import { DEFAULT_THEME_QUERY } from './constants';

/**
* Constants
*/
const REGEXP_SERIALIZED_QUERY = /^(?:(\d+):)?(.*)$/;
const SEARCH_TAXONOMIES = [ 'subject', 'feature', 'color', 'style', 'column', 'layout' ];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not the full set of filter taxonomies. It should probably be pulled from the object here if we really need to know about it. I'm worried about this though, because filtering should be completely transparent to the theme state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait! This is just for testing, right? Phew.

Can we move it into a test folder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait! This is just for testing, right? Phew.

No, not just for testing. This is used by isThemeMatchingQuery, which up until this PR would've been used as ThemeQueryManager's matches() method. Since we're dropping the latter now, only one use remains: client-side filtering of themes obtained from a Jetpack site's endpoint.

We do this here, and it essentially supersedes this stuff.

I'm worried about this though, because filtering should be completely transparent to the theme state.

I'd agree in principle, but as long as the JP endpoint differs from the WPcom one in this regard, I'd filter as early as possible after retrieval from the endpoint to be transparent afterwards.

I can pull the taxonomies from theme-filters. I think the themes list endpoint doesn't return them anyway (only the details one does), and the Jetpack one only returns feature (in the guise of tags, but we normalize that to feature).

Bottom line is that now that we don't use this for TQM, we might actually drop most of the taxonomies except for feature since they're not present in their remaining use case -- JP results filtering -- anyway.

* algorithms on the client side would be non-trivial, or would require a
* heavy (and possibly slow) dependency such as elasticlunr.
* By implementing receive() ourselves instead, we can override the base class
* QueryManager's sorting behavior and keep the order as returned from the endpoint.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is a bit verbose I think. We'd be crazy to implement some ES equivalent in the client, since we have a really fast ES endpoint that returns themes in the exact order we want them.

All we need to say is that the endpoint order is correct already. I think QueryManager exists because some data (posts?) needs to jump around? We don't have that problem, so we don't need to explain why we're not solving it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, if you inherit from QueryManager or PaginatedQueryManager, you're supposed to normally just implement matches and sort (as by the QM README) which is why I'm explaining why we don't do that.

But yeah, it is a bit verbose...

@seear
Copy link
Contributor

seear commented Dec 13, 2016

To test: Check that theme sheets and the Current Theme bar still work. These are the only two places that already use ThemeQueryManager.

I tested theme upload as well, since that also uses ThemeQueryManager ;)

Copy link
Contributor

@seear seear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, let's 🚢 this

Instead of just relying on that of the base class and implementing
matches() and sort() to make use of it.
This is because our themes query REST API endpoint uses ElasticSearch
heavily to sort results by relevancy. Mimicking ES's complex weighting
algorithms on the client side would be non-trivial, or would require a
heavy (and possibly slow) dependency such as elasticlunr.
By implementing receive() ourselves instead, we can override the base class
QueryManager's sorting behavior and keep the order as returned from the endpoint.
It's no longer needed by ThemeQueryManager.
Jetpack sites don't return a `tier` field since all themes on a Jetpack site are free,
so there's no point in filtering by tier.
@ockham ockham force-pushed the add/theme-query-manager-receive-method branch from 51923ae to ebc44e4 Compare December 13, 2016 22:32
@ockham ockham merged commit fe7736e into master Dec 13, 2016
@ockham ockham deleted the add/theme-query-manager-receive-method branch December 13, 2016 22:47
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature Group] Appearance & Themes Features related to the appearance of sites.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants