-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Search indexing with storage #5854
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
Changes from 1 commit
596bed4
a909b36
ea54d0f
a29540e
62863bf
731f8e6
bdc84bd
a3ef36e
207899e
7441b9f
f344eeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1268,7 +1268,6 @@ def fileify(version_pk, commit, build): | |
) | ||
return | ||
|
||
path = project.rtd_build_path(version.slug) | ||
log.info( | ||
LOG_TEMPLATE, | ||
{ | ||
|
@@ -1278,40 +1277,47 @@ def fileify(version_pk, commit, build): | |
} | ||
) | ||
try: | ||
_manage_imported_files(version, path, commit, build) | ||
_manage_imported_files(version, commit, build) | ||
except Exception: | ||
log.exception('Failed during ImportedFile creation') | ||
|
||
try: | ||
_update_intersphinx_data(version, path, commit, build) | ||
_update_intersphinx_data(version, commit, build) | ||
except Exception: | ||
log.exception('Failed during SphinxDomain creation') | ||
|
||
|
||
def _update_intersphinx_data(version, path, commit, build): | ||
def _update_intersphinx_data(version, commit, build): | ||
""" | ||
Update intersphinx data for this version. | ||
|
||
:param version: Version instance | ||
:param path: Path to search | ||
:param commit: Commit that updated path | ||
:param build: Build id | ||
""" | ||
|
||
object_file = os.path.join(path, 'objects.inv') | ||
if not os.path.exists(object_file): | ||
log.debug('No objects.inv, skipping intersphinx indexing.') | ||
if not settings.RTD_BUILD_MEDIA_STORAGE: | ||
return | ||
|
||
full_json_path = version.project.get_production_media_path( | ||
storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() | ||
|
||
html_storage_path = version.project.get_storage_path( | ||
type_='html', version_slug=version.slug, include_file=False | ||
) | ||
json_storage_path = version.project.get_storage_path( | ||
type_='json', version_slug=version.slug, include_file=False | ||
) | ||
type_file = os.path.join(full_json_path, 'readthedocs-sphinx-domain-names.json') | ||
|
||
object_file = storage.join(html_storage_path, 'objects.inv') | ||
if not storage.exists(object_file): | ||
log.debug('No objects.inv, skipping intersphinx indexing.') | ||
return | ||
|
||
type_file = storage.join(json_storage_path, 'readthedocs-sphinx-domain-names.json') | ||
types = {} | ||
titles = {} | ||
if os.path.exists(type_file): | ||
if storage.exists(type_file): | ||
try: | ||
data = json.load(open(type_file)) | ||
data = json.load(storage.open(type_file)) | ||
types = data['types'] | ||
titles = data['titles'] | ||
except Exception: | ||
|
@@ -1331,7 +1337,13 @@ def warn(self, msg): | |
log.warning('Sphinx MockApp: %s', msg) | ||
|
||
# Re-create all objects from the new build of the version | ||
invdata = intersphinx.fetch_inventory(MockApp(), '', object_file) | ||
object_file_url = storage.url(object_file) | ||
if object_file_url.startswith('/'): | ||
# Filesystem backed storage simply prepends MEDIA_URL to the path to get the URL | ||
# This can cause an issue if MEDIA_URL is not fully qualified | ||
object_file_url = 'http://' + settings.PRODUCTION_DOMAIN + object_file_url | ||
|
||
invdata = intersphinx.fetch_inventory(MockApp(), '', object_file_url) | ||
for key, value in sorted(invdata.items() or {}): | ||
domain, _type = key.split(':') | ||
for name, einfo in sorted(value.items()): | ||
|
@@ -1419,29 +1431,36 @@ def clean_build(version_pk): | |
return True | ||
|
||
|
||
def _manage_imported_files(version, path, commit, build): | ||
def _manage_imported_files(version, commit, build): | ||
""" | ||
Update imported files for version. | ||
|
||
:param version: Version instance | ||
:param path: Path to search | ||
:param commit: Commit that updated path | ||
:param build: Build id | ||
""" | ||
|
||
if not settings.RTD_BUILD_MEDIA_STORAGE: | ||
return | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should likely log something here, so we don't get confused if indexing isn't working. |
||
|
||
storage = get_storage_class(settings.RTD_BUILD_MEDIA_STORAGE)() | ||
|
||
changed_files = set() | ||
|
||
# Re-create all objects from the new build of the version | ||
for root, __, filenames in os.walk(path): | ||
storage_path = version.project.get_storage_path( | ||
type_='html', version_slug=version.slug, include_file=False | ||
) | ||
for root, __, filenames in storage.walk(storage_path): | ||
for filename in filenames: | ||
if filename.endswith('.html'): | ||
model_class = HTMLFile | ||
else: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It means we store all ImportedFile's not just HTMLFile's, so we can purge them from the CDN properly when they change. |
||
model_class = ImportedFile | ||
|
||
full_path = os.path.join(root, filename) | ||
relpath = os.path.relpath(full_path, path) | ||
relpath = storage.join(root, filename) | ||
try: | ||
md5 = hashlib.md5(open(full_path, 'rb').read()).hexdigest() | ||
md5 = hashlib.md5(storage.open(relpath, 'rb').read()).hexdigest() | ||
except Exception: | ||
log.exception( | ||
'Error while generating md5 for %s:%s:%s. Don\'t stop.', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe we should be able to get away from this soon. We should be starting to store the proper path of a file after readthedocs/readthedocs-sphinx-ext#62 is merged.