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

11211 - Allow use of graph slugs for ES reindex by type #11212

Draft
wants to merge 8 commits into
base: dev/8.0.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions arches/app/utils/index_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,30 +327,41 @@ def index_resources_by_type(

for resource_type in resource_types:
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
start = datetime.now()
try:
uuid.UUID(str(resource_type))
graph = models.GraphModel.objects.get(graphid=str(resource_type))
Copy link
Member

Choose a reason for hiding this comment

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

This part will have to change because slugs are no longer unique in v8 -- they are shared across graph versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't have a functioning v8 setup here so I'll just put this PR on hold for now until I have the time to get one up and running to sort this out.

except ValueError:
try:
graph = models.GraphModel.objects.get(slug=str(resource_type))
except:
logger.warning(
"Unable to resolve resource type %s. Please confirm it is a valid graph ID or slug."
% resource_type
)
continue
Copy link
Member

Choose a reason for hiding this comment

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

Is there a reason to have the log & continue only under one failure path? A UUID not in the db will still hard-crash.


graph_name = models.GraphModel.objects.get(graphid=str(resource_type)).name
logger.info("Indexing resource type '{0}'".format(graph_name))
logger.info("Indexing resource type '{0}'".format(graph.name))

if clear_index:
tq = Query(se=se)
cards = models.CardModel.objects.filter(
graph_id=str(resource_type)
graph_id=str(graph.graphid)
).select_related("nodegroup")
for nodegroup in [card.nodegroup for card in cards]:
term = Term(field="nodegroupid", term=str(nodegroup.nodegroupid))
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
tq.add_query(term)
tq.delete(index=TERMS_INDEX, refresh=True)

rq = Query(se=se)
term = Term(field="graph_id", term=str(resource_type))
term = Term(field="graph_id", term=str(graph.graphid))
rq.add_query(term)
rq.delete(index=RESOURCES_INDEX, refresh=True)

if use_multiprocessing:
resources = [
str(rid)
for rid in Resource.objects.filter(
graph_id=str(resource_type)
graph_id=str(graph.graphid)
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
).values_list("resourceinstanceid", flat=True)
]
index_resources_using_multiprocessing(
Expand All @@ -366,17 +377,17 @@ def index_resources_by_type(
SearchEngineInstance as _se,
)

resources = Resource.objects.filter(graph_id=str(resource_type))
resources = Resource.objects.filter(graph_id=str(graph.graphid))
index_resources_using_singleprocessing(
resources=resources,
batch_size=batch_size,
quiet=quiet,
title=graph_name,
title=graph.graphid,
recalculate_descriptors=recalculate_descriptors,
)

q = Query(se=se)
term = Term(field="graph_id", term=str(resource_type))
term = Term(field="graph_id", term=str(graph.graphid))
q.add_query(term)
result_summary = {
"database": len(resources),
Expand All @@ -390,7 +401,7 @@ def index_resources_by_type(
logger.info(
"Status: {0}, Resource Type: {1}, In Database: {2}, Indexed: {3}, Took: {4} seconds".format(
status,
graph_name,
graph.graphid,
result_summary["database"],
result_summary["indexed"],
(datetime.now() - start).seconds,
Expand Down
2 changes: 1 addition & 1 deletion arches/management/commands/es.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def add_arguments(self, parser):
action="store",
dest="resource_types",
default="",
help="UUID of resource_model to index resources of.",
help="Comma separated list of resource model UUIDs or slugs to index resources of.",
)

parser.add_argument(
Expand Down
1 change: 1 addition & 0 deletions releases/8.0.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Arches 8.0.0 Release Notes
For more, see (link to forthcoming blog post or documentation? Or arches-lingo?)

### Additional highlights
- 11211 Allow use of graph slug in ES reindex resources management command

### Performance improvements

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/resource_graphs/Resource Test Model.json
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@
"ontologyclass": null,
"sortorder": 0
},
"slug": null,
"slug": "resource_test_model",
"subtitle": "",
"template_id": "50000000-0000-0000-0000-000000000001",
"version": ""
Expand Down
5 changes: 5 additions & 0 deletions tests/models/resource_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def setUpClass(cls):
resource_graph_importer(archesfile["graph"])

cls.search_model_graphid = uuid.UUID("c9b37a14-17b3-11eb-a708-acde48001122")
cls.search_model_slug = "resource_test_model"
cls.search_model_cultural_period_nodeid = "c9b3882e-17b3-11eb-a708-acde48001122"
cls.search_model_creation_date_nodeid = "c9b38568-17b3-11eb-a708-acde48001122"
cls.search_model_destruction_date_nodeid = (
Expand Down Expand Up @@ -288,6 +289,10 @@ def test_reindex_by_resource_type(self):
[self.search_model_graphid], clear_index=True, batch_size=4000
)

result = index_resources_by_type(
[self.search_model_slug], clear_index=True, batch_size=4000
)

self.assertEqual(result, "Passed")

def test_publication_restored_on_save(self):
Expand Down
Loading