Solution for issues 250, 334, 207 which involves calling a refcheck( whether there is any reference to the given DATAID or not) before destroying the DATAID
authorAshutosh Singla <ashu1461@gmail.com>
Sat, 13 Apr 2013 00:54:03 +0530
changeset 2097cd0d3f576ca6
parent 2091 7c00da767896
child 2098 ce204ae5e52d
Solution for issues 250, 334, 207 which involves calling a refcheck( whether there is any reference to the given DATAID or not) before destroying the DATAID
MoinMoin/storage/backends/_tests/__init__.py
MoinMoin/storage/backends/stores.py
MoinMoin/storage/middleware/_tests/test_routing.py
MoinMoin/storage/middleware/indexing.py
MoinMoin/storage/middleware/routing.py
     1.1 --- a/MoinMoin/storage/backends/_tests/__init__.py	Thu Apr 11 21:21:30 2013 +0200
     1.2 +++ b/MoinMoin/storage/backends/_tests/__init__.py	Sat Apr 13 00:54:03 2013 +0530
     1.3 @@ -62,7 +62,7 @@
     1.4          assert m == meta
     1.5          assert d.read() == data
     1.6          d.close()
     1.7 -        self.be.remove(metaid)
     1.8 +        self.be.remove(metaid, destroy_data=True)
     1.9          with pytest.raises(KeyError):
    1.10              self.be.retrieve(metaid)
    1.11  
     2.1 --- a/MoinMoin/storage/backends/stores.py	Thu Apr 11 21:21:30 2013 +0200
     2.2 +++ b/MoinMoin/storage/backends/stores.py	Sat Apr 13 00:54:03 2013 +0530
     2.3 @@ -168,8 +168,9 @@
     2.4      def _del_data(self, dataid):
     2.5          del self.data_store[dataid]
     2.6  
     2.7 -    def remove(self, metaid):
     2.8 +    def remove(self, metaid, destroy_data):
     2.9          meta = self._get_meta(metaid)
    2.10          dataid = meta[DATAID]
    2.11          self._del_meta(metaid)
    2.12 -        self._del_data(dataid)
    2.13 +        if destroy_data:
    2.14 +            self._del_data(dataid)
     3.1 --- a/MoinMoin/storage/middleware/_tests/test_routing.py	Thu Apr 11 21:21:30 2013 +0200
     3.2 +++ b/MoinMoin/storage/middleware/_tests/test_routing.py	Sat Apr 13 00:54:03 2013 +0530
     3.3 @@ -63,8 +63,8 @@
     3.4      assert other_name.split(':')[1] == other_meta[NAME][0]
     3.5  
     3.6      # delete revs:
     3.7 -    router.remove(default_backend_name, default_revid)
     3.8 -    router.remove(other_backend_name, other_revid)
     3.9 +    router.remove(default_backend_name, default_revid, destroy_data=True)
    3.10 +    router.remove(other_backend_name, other_revid, destroy_data=True)
    3.11  
    3.12  
    3.13  def test_store_readonly_fails(router):
     4.1 --- a/MoinMoin/storage/middleware/indexing.py	Thu Apr 11 21:21:30 2013 +0200
     4.2 +++ b/MoinMoin/storage/middleware/indexing.py	Sat Apr 13 00:54:03 2013 +0530
     4.3 @@ -75,7 +75,7 @@
     4.4  from MoinMoin.constants.keys import (WIKINAME, NAMESPACE, NAME, NAME_EXACT, MTIME, CONTENTTYPE, TAGS, LANGUAGE,
     4.5                                       USERID, ADDRESS, HOSTNAME, SIZE, ACTION, COMMENT, SUMMARY, CONTENT,
     4.6                                       EXTERNALLINKS, ITEMLINKS, ITEMTRANSCLUSIONS, ACL, DISABLED, EMAIL, OPENID,
     4.7 -                                     ITEMID, REVID, CURRENT, PARENTID, PTIME, LATEST_REVS, ALL_REVS, BACKENDNAME)
     4.8 +                                     ITEMID, REVID, CURRENT, PARENTID, PTIME, LATEST_REVS, ALL_REVS, BACKENDNAME, DATAID)
     4.9  from MoinMoin.constants.contenttypes import CONTENTTYPE_USER
    4.10  from MoinMoin.constants.namespaces import NAMESPACE_DEFAULT
    4.11  from MoinMoin.constants import keys
    4.12 @@ -301,6 +301,8 @@
    4.13              COMMENT: TEXT(stored=True),
    4.14              # SUMMARY from metadata
    4.15              SUMMARY: TEXT(stored=True),
    4.16 +            # DATAID from metadata
    4.17 +            DATAID: ID(stored=True),
    4.18              # data (content), converted to text/plain and tokenized
    4.19              CONTENT: TEXT(stored=True),
    4.20          }
    4.21 @@ -1111,7 +1113,10 @@
    4.22          Destroy revision <revid>.
    4.23          """
    4.24          rev = Revision(self, revid)
    4.25 -        self.backend.remove(rev.backend_name, revid)
    4.26 +        query = {DATAID: rev.meta[DATAID]}
    4.27 +        with flaskg.storage.indexer.ix[ALL_REVS].searcher() as searcher:
    4.28 +            refcount = len(list(searcher.document_numbers(**query)))
    4.29 +        self.backend.remove(rev.backend_name, revid, destroy_data=refcount == 1)
    4.30          self.indexer.remove_revision(revid)
    4.31  
    4.32      def destroy_all_revisions(self):
     5.1 --- a/MoinMoin/storage/middleware/routing.py	Thu Apr 11 21:21:30 2013 +0200
     5.2 +++ b/MoinMoin/storage/middleware/routing.py	Sat Apr 13 00:54:03 2013 +0530
     5.3 @@ -132,8 +132,8 @@
     5.4          meta[BACKENDNAME] = backend_name
     5.5          return backend_name, revid
     5.6  
     5.7 -    def remove(self, backend_name, revid):
     5.8 +    def remove(self, backend_name, revid, destroy_data):
     5.9          backend = self.backends[backend_name]
    5.10          if not isinstance(backend, MutableBackendBase):
    5.11              raise TypeError('backend {0} is readonly'.format(backend_name))
    5.12 -        backend.remove(revid)
    5.13 +        backend.remove(revid, destroy_data)