@@ -1621,8 +1621,9 @@ def _sync_imported_files(version, build, changed_files):
1621
1621
# Remove old HTMLFiles from ElasticSearch
1622
1622
remove_indexed_files (
1623
1623
model = HTMLFile ,
1624
- version = version ,
1625
- build = build ,
1624
+ project_slug = version .project .slug ,
1625
+ version_slug = version .slug ,
1626
+ build_id = build ,
1626
1627
)
1627
1628
1628
1629
# Delete SphinxDomain objects from previous versions
@@ -1844,6 +1845,17 @@ def remove_build_storage_paths(paths):
1844
1845
storage .delete_directory (storage_path )
1845
1846
1846
1847
1848
+ @app .task (queue = 'web' )
1849
+ def remove_search_indexes (project_slug , version_slug = None ):
1850
+ """Wrapper around `remove_indexed_files to make it a task."""
1851
+ # Remove ES indexes
1852
+ remove_indexed_files (
1853
+ model = HTMLFile ,
1854
+ project_slug = project_slug ,
1855
+ version_slug = version_slug ,
1856
+ )
1857
+
1858
+
1847
1859
def clean_project_resources (project , version = None ):
1848
1860
"""
1849
1861
Delete all extra resources used by `version` of `project`.
@@ -1853,16 +1865,27 @@ def clean_project_resources(project, version=None):
1853
1865
- Artifacts from storage.
1854
1866
- Search indexes from ES.
1855
1867
1856
- :param version: Version instance. if isn't given,
1868
+ :param version: Version instance. If isn't given,
1857
1869
all resources of `project` will be deleted.
1870
+
1871
+ .. note::
1872
+ This function is usually called just before deleting project.
1873
+ Make sure to not depend on the project object inside the tasks.
1858
1874
"""
1875
+ # Remove storage paths
1859
1876
storage_paths = []
1860
1877
if version :
1861
1878
version .get_storage_paths ()
1862
1879
else :
1863
1880
storage_paths = project .get_storage_paths ()
1864
1881
remove_build_storage_paths .delay (storage_paths )
1865
1882
1883
+ # Remove indexes
1884
+ remove_search_indexes .delay (
1885
+ project_slug = project .slug ,
1886
+ version_slug = version .slug if version else None ,
1887
+ )
1888
+
1866
1889
1867
1890
@app .task (queue = 'web' )
1868
1891
def sync_callback (_ , version_pk , commit , build , * args , ** kwargs ):
0 commit comments