Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Include deleted & mature existence checks when updating indices (#365)
Madison Swain-Bowden8bf0ce53ccfe
diff --git a/ingestion_server/ingestion_server/indexer.py b/ingestion_server/ingestion_server/indexer.pyindex fb898ea1f..b8063819f 100644--- a/ingestion_server/ingestion_server/indexer.py+++ b/ingestion_server/ingestion_server/indexer.py@@ -414,9 +414,17 @@ class TableIndexer:def update(self, model_name: str, since_date):log.info(f"Updating index {model_name} with changes since {since_date}")+ deleted, mature = get_existence_queries(model_name)query = SQL(- "SELECT * FROM {model_name} " "WHERE updated_on >= {since_date};"- ).format(model_name=Identifier(model_name), since_date=Literal(since_date))+ "SELECT *, {deleted}, {mature} "+ "FROM {model_name} "+ "WHERE updated_on >= {since_date};"+ ).format(+ deleted=deleted,+ mature=mature,+ model_name=Identifier(model_name),+ since_date=Literal(since_date),+ )self.replicate(model_name, model_name, query)@staticmethoddiff --git a/ingestion_server/test/integration_test.py b/ingestion_server/test/integration_test.pyindex 0e31530d8..dc36b9f77 100644--- a/ingestion_server/test/integration_test.py+++ b/ingestion_server/test/integration_test.py@@ -320,3 +320,41 @@ class TestIngestion(unittest.TestCase):search_response = es.search(index="audio", body=es_query)msg = "There should be 5000 audio tracks in Elasticsearch after ingestion."self.assertEquals(search_response["hits"]["total"]["value"], 5000, msg)++ @pytest.mark.order(8)+ def test_update_index_images(self):+ """+ Check that the image data can be updated from the API database into+ Elasticsearch.+ """+ req = {+ "model": "image",+ "action": "UPDATE_INDEX",+ "since_date": "1999-01-01",+ "callback_url": bottle_url,+ }+ res = requests.post(f"{ingestion_server}/task", json=req)+ stat_msg = "The job should launch successfully and return 202 ACCEPTED."+ self.assertEqual(res.status_code, 202, msg=stat_msg)++ # Wait for the task to send us a callback.+ assert self.__class__.cb_queue.get(timeout=120) == "CALLBACK!"++ @pytest.mark.order(9)+ def test_update_index_audio(self):+ """+ Check that the audio data can be updated from the API database into+ Elasticsearch.+ """+ req = {+ "model": "audio",+ "action": "UPDATE_INDEX",+ "since_date": "1999-01-01",+ "callback_url": bottle_url,+ }+ res = requests.post(f"{ingestion_server}/task", json=req)+ stat_msg = "The job should launch successfully and return 202 ACCEPTED."+ self.assertEqual(res.status_code, 202, msg=stat_msg)++ # Wait for the task to send us a callback.+ assert self.__class__.cb_queue.get(timeout=120) == "CALLBACK!"