1
0
mirror of https://github.com/djohnlewis/stackdump synced 2025-04-07 10:13:27 +00:00

Fixed a bug with the previous commit - site object cannot be accessed after transaction has been committed.

Also added an argument so deletes are expunged from the index immediately.
This commit is contained in:
Samuel Lai 2012-08-12 14:11:16 +10:00
parent 6ef90b2ad2
commit fdf31a3ef6

@ -49,13 +49,14 @@ def delete_site(site_key):
solr = Solr("http://localhost:8983/solr/") solr = Solr("http://localhost:8983/solr/")
print('Connected.\n') print('Connected.\n')
site_name = None
site = Site.select(Site.q.key==site_key).getOne(None) site = Site.select(Site.q.key==site_key).getOne(None)
if not site: if not site:
print 'Site key "%s" does not exist in database.\n' % site_key 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 # continuing at this point means any orphaned entries in solr are
# import was aborted so the db transaction was rolled back, but not # deleted as well.
# entries in solr) are deleted as well.
else: else:
site_name = site.name
sqlhub.threadConnection = sqlhub.processConnection.transaction() sqlhub.threadConnection = sqlhub.processConnection.transaction()
print('Deleting site "%s" from the database... ' % site.name) print('Deleting site "%s" from the database... ' % site.name)
@ -65,8 +66,12 @@ def delete_site(site_key):
sqlhub.threadConnection.commit(close=True) sqlhub.threadConnection.commit(close=True)
print('Deleting site "%s" from solr... ' % (site and site.name or site_key)) if site_name:
solr.delete(q='siteKey:"%s"' % site_key) print('Deleting site "%s" from solr... ' % site_name)
else:
print('Deleting site with key "%s" from solr... ' % site_key)
solr.delete(q='siteKey:"%s"' % site_key, commit=False)
solr.commit(expungeDeletes=True)
print('Deleted.\n') print('Deleted.\n')
# END FUNCTIONS # END FUNCTIONS