From 1fedab16ac788251da62e996f737ea203ee88d7c Mon Sep 17 00:00:00 2001 From: Nathan Franklin Date: Tue, 11 Jun 2024 17:12:03 -0500 Subject: [PATCH 1/2] Fix command to reindex dev ElasticSearch (#1288) --- .../apps/data/management/commands/es_setup.py | 89 +++++++++---------- 1 file changed, 42 insertions(+), 47 deletions(-) diff --git a/designsafe/apps/data/management/commands/es_setup.py b/designsafe/apps/data/management/commands/es_setup.py index 60a6db910f..5be0b749ba 100644 --- a/designsafe/apps/data/management/commands/es_setup.py +++ b/designsafe/apps/data/management/commands/es_setup.py @@ -29,58 +29,53 @@ def add_arguments(self, parser): parser.add_argument('--local', help='Remote role to index from, either staging or default', default="dev") def handle(self, *args, **options): - HOSTS = settings.ES_CONNECTIONS[settings.DESIGNSAFE_ENVIRONMENT]['hosts'] password = getpass.getpass('Enter password for remote ES cluster ') username = options.get('username') remote = options.get('remote') local = options.get('local') - local_es_client = elasticsearch.Elasticsearch(settings.ES_CONNECTIONS[local]['hosts']) + local_es_client = elasticsearch.Elasticsearch(settings.ES_CONNECTIONS[local]['hosts'], + timeout=300) remote_es_client = elasticsearch.Elasticsearch(settings.ES_CONNECTIONS[remote]['hosts'], - **{'http_auth': "designsafe_{}:{}".format(remote, password)}) + **{'http_auth': "designsafe_{}:{}".format(remote, password)}, + timeout=300) + def reindex(source_index, target_index, query=None): + try: + response = elasticsearch.helpers.reindex( + client=remote_es_client, + target_client=local_es_client, + source_index=source_index, + target_index=target_index, + query=query, + ) + logger.info(f"Reindexed {response} documents from {source_index} to {target_index}") + except elasticsearch.helpers.BulkIndexError as e: + logger.error(f"BulkIndexError: {e.errors}") + logger.error(f"Failed to reindex documents from {source_index} to {target_index}") + return False + return response + indexes = ["designsafe-{}-files", + "designsafe-{}-publications", + "designsafe-{}-publications-legacy", + "designsafe-{}-projects", + "designsafe-{}-rapid-events", + "designsafe-{}-rapid-event-types" + ] - elasticsearch.helpers.reindex( - client=remote_es_client, - target_client=local_es_client, - source_index="designsafe-{}-files".format(remote), - target_index="designsafe-{}-files".format(local), - query={"query": {"prefix": {"path._exact": "/{}".format(username)}}} - ) - - elasticsearch.helpers.reindex( - client=remote_es_client, - target_client=local_es_client, - source_index="designsafe-{}-publications".format(remote), - target_index="designsafe-{}-publications".format(local) - ) - - elasticsearch.helpers.reindex( - client=remote_es_client, - target_client=local_es_client, - source_index="designsafe-{}-publications-legacy".format(remote), - target_index="designsafe-{}-publications-legacy".format(local) - ) - - elasticsearch.helpers.reindex( - client=remote_es_client, - target_client=local_es_client, - source_index="designsafe-{}-projects".format(remote), - target_index="designsafe-{}-projects".format(local) - ) - - elasticsearch.helpers.reindex( - client=remote_es_client, - target_client=local_es_client, - source_index="designsafe-{}-rapid-events".format(remote), - target_index="designsafe-{}-rapid-events".format(local) - ) - - elasticsearch.helpers.reindex( - client=remote_es_client, - target_client=local_es_client, - source_index="designsafe-{}-rapid-event-types".format(remote), - target_index="designsafe-{}-rapid-event-types".format(local) - ) - - logger.debug(remote_es_client.info()) + failed_indexes = [] + for index in indexes: + query = {"query": {"prefix": {"path._exact": "/{}".format(username)}}} if "files" in index else None + result = reindex( + source_index=index.format(remote), + target_index=index.format(local), + query=query + ) + if not result: + failed_indexes.append(index.format(local)) + logger.info("Finished indexing.") + if failed_indexes: + logger.error(f"Successfully reindex {len(indexes) - len(failed_indexes)}" + f" of {len(indexes)} indexes\n" + f"failed indexes are: {', '.join(failed_indexes)}\n" + f"(check logs above for errors related to failures)") From ef085e433e99c18b647ba1a4953e9e79cb3002b2 Mon Sep 17 00:00:00 2001 From: Nathan Franklin Date: Tue, 11 Jun 2024 17:15:41 -0500 Subject: [PATCH 2/2] Prevent zooming out and endless scrolling in ReconPortal (#1289) Co-authored-by: Sal Tijerina --- .../static/scripts/rapid/controllers/rapid-main-ctrl.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/designsafe/static/scripts/rapid/controllers/rapid-main-ctrl.js b/designsafe/static/scripts/rapid/controllers/rapid-main-ctrl.js index 3c1b70dfe0..3f0c00f0bf 100644 --- a/designsafe/static/scripts/rapid/controllers/rapid-main-ctrl.js +++ b/designsafe/static/scripts/rapid/controllers/rapid-main-ctrl.js @@ -46,7 +46,12 @@ export default class RapidMainCtrl { ); this.map = L.map('map', { layers: [streets, satellite], - scrollWheelZoom: true + scrollWheelZoom: true, + minZoom: 2, // 2 typically prevents zooming out to far to see multiple earths + maxBounds: [ + [-90, -180], // Southwest coordinates + [90, 180], // Northeast coordinates + ] }); this.map.setView([30.2672, -97.7431], 2); this.map.zoomControl.setPosition('topright');