1
0
mirror of https://github.com/djohnlewis/stackdump synced 2024-12-04 23:17:37 +00:00

Orphaned entries in solr are also deleted.

Entries are considered orphaned if there is no corresponding database entry, e.g. if an import operation was aborted and hence the database entries were rolled back, but the solr ones were not.
This commit is contained in:
Samuel Lai 2012-08-07 22:28:21 +10:00
parent 9c2e530eff
commit 6ef90b2ad2

View File

@ -51,21 +51,23 @@ def delete_site(site_key):
site = Site.select(Site.q.key==site_key).getOne(None)
if not site:
print 'Site key %s does not exist.' % site_key
sys.exit(1)
print 'Site key "%s" does not exist in database.\n' % site_key
# continuing at this point means orphaned entries in solr (e.g. if an
# import was aborted so the db transaction was rolled back, but not
# entries in solr) are deleted as well.
else:
sqlhub.threadConnection = sqlhub.processConnection.transaction()
print('Deleting site "%s" from the database... ' % site.name)
sys.stdout.flush()
Site.delete(site.id) # the relationship cascades, so other rows will be deleted
print('Deleted.\n')
sqlhub.threadConnection.commit(close=True)
sqlhub.threadConnection = sqlhub.processConnection.transaction()
print('Deleting site "%s" from the database... ' % site.name)
sys.stdout.flush()
Site.delete(site.id) # the relationship cascades, so other rows will be deleted
print('Deleted.\n')
print('Deleting site "%s" from solr... ' % site.name)
print('Deleting site "%s" from solr... ' % (site and site.name or site_key))
solr.delete(q='siteKey:"%s"' % site_key)
print('Deleted.\n')
sqlhub.threadConnection.commit(close=True)
# END FUNCTIONS