@@ -1340,15 +1340,14 @@ def fileify(version_pk, commit, build, search_ranking, search_ignore):
1340
1340
},
1341
1341
)
1342
1342
try :
1343
- changed_files = _create_imported_files (
1343
+ _create_imported_files (
1344
1344
version = version ,
1345
1345
commit = commit ,
1346
1346
build = build ,
1347
1347
search_ranking = search_ranking ,
1348
1348
search_ignore = search_ignore ,
1349
1349
)
1350
1350
except Exception :
1351
- changed_files = set ()
1352
1351
log .exception ('Failed during ImportedFile creation' )
1353
1352
1354
1353
try :
@@ -1357,7 +1356,7 @@ def fileify(version_pk, commit, build, search_ranking, search_ignore):
1357
1356
log .exception ('Failed during SphinxDomain creation' )
1358
1357
1359
1358
try :
1360
- _sync_imported_files (version , build , changed_files )
1359
+ _sync_imported_files (version , build )
1361
1360
except Exception :
1362
1361
log .exception ('Failed during ImportedFile syncing' )
1363
1362
@@ -1530,57 +1529,22 @@ def _create_imported_files(*, version, commit, build, search_ranking, search_ign
1530
1529
:param version: Version instance
1531
1530
:param commit: Commit that updated path
1532
1531
:param build: Build id
1533
- :returns: paths of changed files
1534
- :rtype: set
1535
1532
"""
1536
- changed_files = set ()
1537
-
1538
1533
# Re-create all objects from the new build of the version
1539
1534
storage_path = version .project .get_storage_path (
1540
1535
type_ = 'html' , version_slug = version .slug , include_file = False
1541
1536
)
1542
1537
for root , __ , filenames in build_media_storage .walk (storage_path ):
1543
1538
for filename in filenames :
1544
- if filename .endswith ('.html' ):
1545
- model_class = HTMLFile
1546
- elif version .project .cdn_enabled :
1547
- # We need to track all files for CDN enabled projects so the files can be purged
1548
- model_class = ImportedFile
1549
- else :
1550
- # For projects not behind a CDN, we don't care about non-HTML
1539
+ # We don't care about non-HTML files
1540
+ if not filename .endswith ('.html' ):
1551
1541
continue
1552
1542
1553
1543
full_path = build_media_storage .join (root , filename )
1554
1544
1555
1545
# Generate a relative path for storage similar to os.path.relpath
1556
1546
relpath = full_path .replace (storage_path , '' , 1 ).lstrip ('/' )
1557
1547
1558
- try :
1559
- md5 = hashlib .md5 (build_media_storage .open (full_path , 'rb' ).read ()).hexdigest ()
1560
- except Exception :
1561
- log .exception (
1562
- 'Error while generating md5 for %s:%s:%s. Don\' t stop.' ,
1563
- version .project .slug ,
1564
- version .slug ,
1565
- relpath ,
1566
- )
1567
- md5 = ''
1568
- # Keep track of changed files to be purged in the CDN
1569
- obj = (
1570
- model_class .objects
1571
- .filter (project = version .project , version = version , path = relpath )
1572
- .order_by ('-modified_date' )
1573
- .first ()
1574
- )
1575
- if obj and md5 and obj .md5 != md5 :
1576
- changed_files .add (
1577
- resolve_path (
1578
- version .project ,
1579
- filename = relpath ,
1580
- version_slug = version .slug ,
1581
- ),
1582
- )
1583
-
1584
1548
page_rank = 0
1585
1549
# Last pattern to match takes precedence
1586
1550
# XXX: see if we can implement another type of precedence,
@@ -1598,37 +1562,31 @@ def _create_imported_files(*, version, commit, build, search_ranking, search_ign
1598
1562
break
1599
1563
1600
1564
# Create imported files from new build
1601
- model_class .objects .create (
1565
+ HTMLFile .objects .create (
1602
1566
project = version .project ,
1603
1567
version = version ,
1604
1568
path = relpath ,
1605
1569
name = filename ,
1606
- md5 = md5 ,
1607
1570
rank = page_rank ,
1608
1571
commit = commit ,
1609
1572
build = build ,
1610
1573
ignore = ignore ,
1611
1574
)
1612
1575
1613
- # This signal is used for clearing the CDN,
1614
- # so send it as soon as we have the list of changed files
1576
+ # This signal is used for purging the CDN.
1615
1577
files_changed .send (
1616
1578
sender = Project ,
1617
1579
project = version .project ,
1618
1580
version = version ,
1619
- files = changed_files ,
1620
1581
)
1621
1582
1622
- return changed_files
1623
-
1624
1583
1625
- def _sync_imported_files (version , build , changed_files ):
1584
+ def _sync_imported_files (version , build ):
1626
1585
"""
1627
1586
Sync/Update/Delete ImportedFiles objects of this version.
1628
1587
1629
1588
:param version: Version instance
1630
1589
:param build: Build id
1631
- :param changed_files: path of changed files
1632
1590
"""
1633
1591
1634
1592
# Index new HTMLFiles to ElasticSearch
0 commit comments