Skip to content

Commit

Permalink
WCM-575: remove feature flag contentquery_custom_as_sql (#977)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sinnaj94 authored Jan 16, 2025
1 parent f6d1050 commit 9e31618
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 439 deletions.
1 change: 1 addition & 0 deletions core/docs/changelog/WCM-575.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
WCM-575: remove feature flag contentquery_custom_as_sql
312 changes: 7 additions & 305 deletions core/src/zeit/content/cp/tests/test_automatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import transaction
import zope.component

from zeit.cms.content.sources import FEATURE_TOGGLES
from zeit.cms.testcontenttype.testcontenttype import ExampleContentType
from zeit.content.cp.interfaces import IRenderedArea
import zeit.cms.content.interfaces
Expand Down Expand Up @@ -144,260 +143,6 @@ def test_it_returns_content_objects_provided_by_elasticsearch(self):
self.elasticsearch.search.call_args,
)

def test_builds_query_from_conditions(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
source = zeit.cms.content.interfaces.ICommonMetadata['serie'].source(None)
autotest = source.find('Autotest')
lead.query = (('serie', 'eq', autotest),)
lead.automatic = True
lead.automatic_type = 'custom'
IRenderedArea(lead).values()
self.assertEqual(
{
'query': {
'bool': {
'filter': [
{
'bool': {
'filter': [
{'term': {'payload.document.serie': 'Autotest'}},
]
}
},
{'term': {'payload.workflow.published': True}},
],
'must_not': [
{'term': {'payload.zeit__DOT__content__DOT__gallery.type': 'inline'}}
],
}
},
'sort': [{'payload.workflow.date_last_published_semantic': 'desc'}],
},
self.elasticsearch.search.call_args[0][0],
)

def test_builds_query_with_elasticsearch_fieldname_exceptions(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
lead.query = (
('channels', 'eq', 'International', 'Nahost'),
('channels', 'eq', 'Wissen', None),
)
lead.automatic = True
lead.automatic_type = 'custom'
IRenderedArea(lead).values()
self.assertEqual(
{
'query': {
'bool': {
'filter': [
{
'bool': {
'filter': [
{
'bool': {
'should': [
{
'term': {
'payload.document.channels.hierarchy': 'International Nahost'
}
},
{
'term': {
'payload.document.channels.hierarchy': 'Wissen'
}
},
]
}
},
]
}
},
{'term': {'payload.workflow.published': True}},
],
'must_not': [
{'term': {'payload.zeit__DOT__content__DOT__gallery.type': 'inline'}}
],
}
},
'sort': [{'payload.workflow.date_last_published_semantic': 'desc'}],
},
self.elasticsearch.search.call_args[0][0],
)

def test_builds_query_with_condition_exception(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
lead.query = (
('ressort', 'eq', 'International', 'Nahost'),
('ressort', 'eq', 'Wissen', None),
)
lead.automatic = True
lead.automatic_type = 'custom'
IRenderedArea(lead).values()
self.assertEqual(
{
'query': {
'bool': {
'filter': [
{
'bool': {
'filter': [
{
'bool': {
'should': [
{
'bool': {
'must': [
{
'term': {
'payload.document.ressort': 'International'
}
},
{
'term': {
'payload.document.sub_ressort': 'Nahost'
}
},
]
}
},
{
'term': {
'payload.document.ressort': 'Wissen'
}
},
]
}
},
]
}
},
{'term': {'payload.workflow.published': True}},
],
'must_not': [
{'term': {'payload.zeit__DOT__content__DOT__gallery.type': 'inline'}}
],
}
},
'sort': [{'payload.workflow.date_last_published_semantic': 'desc'}],
},
self.elasticsearch.search.call_args[0][0],
)

def test_joins_different_fields_with_AND_but_same_fields_with_OR(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
source = zeit.cms.content.interfaces.ICommonMetadata['serie'].source(None)
autotest = source.find('Autotest')
lead.query = (
('channels', 'eq', 'International', 'Nahost'),
('channels', 'eq', 'Wissen', None),
('serie', 'eq', autotest),
('ressort', 'eq', 'Wissen', None),
)
lead.automatic = True
lead.automatic_type = 'custom'
IRenderedArea(lead).values()
self.assertEqual(
{
'query': {
'bool': {
'filter': [
{
'bool': {
'filter': [
{
'bool': {
'should': [
{
'term': {
'payload.document.channels.hierarchy': 'International Nahost'
}
},
{
'term': {
'payload.document.channels.hierarchy': 'Wissen'
}
},
]
}
},
{'term': {'payload.document.serie': 'Autotest'}},
{'term': {'payload.document.ressort': 'Wissen'}},
]
}
},
{'term': {'payload.workflow.published': True}},
],
'must_not': [
{'term': {'payload.zeit__DOT__content__DOT__gallery.type': 'inline'}}
],
}
},
'sort': [{'payload.workflow.date_last_published_semantic': 'desc'}],
},
self.elasticsearch.search.call_args[0][0],
)

def test_puts_fields_into_bool_according_to_operator(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
source = zeit.cms.content.interfaces.ICommonMetadata['serie'].source(None)
autotest = source.find('Autotest')
lead.query = (
('channels', 'eq', 'International', 'Nahost'),
('channels', 'eq', 'Wissen', None),
('serie', 'eq', autotest),
('ressort', 'neq', 'Wissen', None),
)
lead.automatic = True
lead.automatic_type = 'custom'
IRenderedArea(lead).values()
self.assertEqual(
{
'query': {
'bool': {
'filter': [
{
'bool': {
'filter': [
{
'bool': {
'should': [
{
'term': {
'payload.document.channels.hierarchy': 'International Nahost'
}
},
{
'term': {
'payload.document.channels.hierarchy': 'Wissen'
}
},
]
}
},
{'term': {'payload.document.serie': 'Autotest'}},
],
'must_not': [
{'term': {'payload.document.ressort': 'Wissen'}},
],
}
},
{'term': {'payload.workflow.published': True}},
],
'must_not': [
{'term': {'payload.zeit__DOT__content__DOT__gallery.type': 'inline'}}
],
}
},
'sort': [{'payload.workflow.date_last_published_semantic': 'desc'}],
},
self.elasticsearch.search.call_args[0][0],
)

def test_can_take_over_whole_query_body(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
Expand Down Expand Up @@ -433,61 +178,12 @@ def test_adds_hide_dupes_clause_to_whole_query_body(self):
self.elasticsearch.search.call_args[0][0]['query'],
)

def test_custom_query_order_defaults_to_semantic_publish(self):
self.area.automatic_type = 'custom'
IRenderedArea(self.area).values()
self.assertEqual(
[{'payload.workflow.date_last_published_semantic': 'desc'}],
self.elasticsearch.search.call_args[0][0]['sort'],
)

def test_custom_query_can_be_forced_to_elastic(self):
FEATURE_TOGGLES.set('contentquery_custom_as_sql')
self.area.automatic_type = 'custom'
self.area.query = (('ressort', 'eq', 'International', 'Nahost'),)
self.area.xml.find('query').set('type', 'elastic')
IRenderedArea(self.area).values()
self.assertTrue(self.elasticsearch.search.called)

def test_query_order_can_be_set(self):
self.area.elasticsearch_raw_order = 'order:desc'
IRenderedArea(self.area).values()
query = self.elasticsearch.search.call_args[0][0]
self.assertEqual([{'order': 'desc'}], query['sort'])

def test_bbb_converts_automatic_type_channel_to_custom(self):
lead = self.repository['cp'].body['lead']
lead.count = 1
source = zeit.cms.content.interfaces.ICommonMetadata['serie'].source(None)
autotest = source.find('Autotest')
lead.query = (('serie', 'eq', autotest),)
lead.automatic = True
lead.xml.set('automatic_type', 'channel')
IRenderedArea(lead).values()
self.assertEqual(
{
'query': {
'bool': {
'filter': [
{
'bool': {
'filter': [
{'term': {'payload.document.serie': 'Autotest'}},
]
}
},
{'term': {'payload.workflow.published': True}},
],
'must_not': [
{'term': {'payload.zeit__DOT__content__DOT__gallery.type': 'inline'}}
],
}
},
'sort': [{'payload.workflow.date_last_published_semantic': 'desc'}],
},
self.elasticsearch.search.call_args[0][0],
)

def test_valid_query_despite_missing_order(self):
self.area.elasticsearch_raw_query = '{"query": {}}'
self.area.elasticsearch_raw_order = ''
Expand Down Expand Up @@ -1205,7 +901,6 @@ def setUp(self):
self.area.automatic_type = 'custom'
self.repository['cp'] = self.cp
self.connector = zope.component.getUtility(zeit.connector.interfaces.IConnector)
FEATURE_TOGGLES.set('contentquery_custom_as_sql')

def test_builds_query_from_conditions(self):
source = zeit.cms.content.interfaces.ICommonMetadata['serie'].source(None)
Expand Down Expand Up @@ -1305,3 +1000,10 @@ def test_print_queries(self):
ORDER BY print_page asc...
"""
self.assertEllipsis(query, self.connector.search_args[0])

def test_custom_query_order_defaults_to_semantic_publish(self):
self.area.automatic_type = 'custom'
self.area.query = (('ressort', 'eq', 'International', 'Nahost'),)
IRenderedArea(self.area).values()
query = '...ORDER BY date_last_published_semantic desc...'
self.assertEllipsis(query, self.connector.search_args[0])
17 changes: 1 addition & 16 deletions core/src/zeit/contentquery/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,6 @@ def referenced_cp(self):
def referenced_cp(self, value):
self._referenced_cp = value

# For automatic_type=custom
_query_order = zeit.cms.content.property.ObjectPathProperty(
'.query_order', IConfiguration['query_order'], use_default=True
)

@property
def query_order(self):
from zeit.contentquery.query import CustomContentQuery # break cycle

value = self._query_order
return CustomContentQuery.ES_ORDER_BWCOMPAT.get(value, value)

@query_order.setter
def query_order(self, value):
self._query_order = value

for name, default in {
# For automatic_type=topicpage
'referenced_topicpage': False,
Expand All @@ -155,6 +139,7 @@ def query_order(self, value):
'reach_access': False,
'reach_age': False,
# For automatic_type=custom
'query_order': True,
'query_restrict_time': True,
'query_force_queryplan': False,
# For automatic_type=sql-query
Expand Down
Loading

0 comments on commit 9e31618

Please sign in to comment.