Elastic: regenerate picture URL before inserting into ElasticSearch
This ensures the thumbnail URL is public so that it won't expire. Since this now requires API calls to Google, I've increased the number of parallel threads used for indexing, since they'll be waiting for network I/O more.
This commit is contained in:
@@ -338,7 +338,7 @@ def process_file(bucket: Bucket,
|
|||||||
file_id, status, r)
|
file_id, status, r)
|
||||||
|
|
||||||
|
|
||||||
def generate_link(backend, file_path: str, project_id=None, is_public=False) -> str:
|
def generate_link(backend, file_path: str, project_id: str=None, is_public=False) -> str:
|
||||||
"""Hook to check the backend of a file resource, to build an appropriate link
|
"""Hook to check the backend of a file resource, to build an appropriate link
|
||||||
that can be used by the client to retrieve the actual file.
|
that can be used by the client to retrieve the actual file.
|
||||||
"""
|
"""
|
||||||
|
@@ -29,21 +29,25 @@ def _get_node_from_id(node_id: str):
|
|||||||
|
|
||||||
|
|
||||||
def _handle_picture(node: dict, to_index: dict):
|
def _handle_picture(node: dict, to_index: dict):
|
||||||
"""
|
"""Add picture URL in-place to the to-be-indexed node."""
|
||||||
add picture fields to be indexed
|
|
||||||
"""
|
|
||||||
|
|
||||||
if not node.get('picture'):
|
picture_id = node.get('picture')
|
||||||
|
if not picture_id:
|
||||||
return
|
return
|
||||||
|
|
||||||
files_collection = current_app.data.driver.db['files']
|
files_collection = current_app.data.driver.db['files']
|
||||||
lookup = {'_id': ObjectId(node['picture'])}
|
lookup = {'_id': ObjectId(picture_id)}
|
||||||
picture = files_collection.find_one(lookup)
|
picture = files_collection.find_one(lookup)
|
||||||
|
|
||||||
for item in picture.get('variations', []):
|
for item in picture.get('variations', []):
|
||||||
if item['size'] != 't':
|
if item['size'] != 't':
|
||||||
continue
|
continue
|
||||||
to_index['picture'] = item['link']
|
|
||||||
|
link = generate_link(picture['backend'],
|
||||||
|
item['file_path'],
|
||||||
|
str(picture['project']),
|
||||||
|
is_public=True)
|
||||||
|
to_index['picture'] = link
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
|
@@ -17,7 +17,7 @@ name_to_task = {
|
|||||||
'nodes': index.ResetNodeIndex,
|
'nodes': index.ResetNodeIndex,
|
||||||
'users': index.ResetUserIndex,
|
'users': index.ResetUserIndex,
|
||||||
}
|
}
|
||||||
REINDEX_THREAD_COUNT = 3
|
REINDEX_THREAD_COUNT = 5
|
||||||
|
|
||||||
|
|
||||||
@manager_elastic.option('indices', nargs='*')
|
@manager_elastic.option('indices', nargs='*')
|
||||||
|
Reference in New Issue
Block a user