changeset 1118:156d160b1dd9

Load the IWID and the meta dict lazily.
author Alexander Schremmer <alex AT alexanderweb DOT de>
date Mon, 31 Jul 2006 12:01:57 +0200
parents 2aa53ed0afa0
children 397b97122ad9
files MoinMoin/config/multiconfig.py docs/CHANGES.aschremmer
diffstat 2 files changed, 24 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/config/multiconfig.py	Mon Jul 31 11:20:22 2006 +0200
+++ b/MoinMoin/config/multiconfig.py	Mon Jul 31 12:01:57 2006 +0200
@@ -552,17 +552,33 @@
 
         # check if mail is possible and set flag:
         self.mail_enabled = (self.mail_smarthost is not None or self.mail_sendmail is not None) and self.mail_from
-        
-        self.meta_dict = wikiutil.MetaDict(os.path.join(data_dir, 'meta'), self.cache_dir)
 
-        # interwiki ID processing
-        self.load_IWID()
+        # Cache variables for the properties below
+        self._iwid = self._iwid_full = self._meta_dict = None
+
+    def load_meta_dict(self):
+        """ The meta_dict contains meta data about the wiki instance. """
+        if getattr(self, "_meta_dict", None) is None:
+            self._meta_dict = wikiutil.MetaDict(os.path.join(self.data_dir, 'meta'), self.cache_dir)
+        return self._meta_dict
+    meta_dict = property(load_meta_dict)
+
+    # lazily load iwid(_full)
+    def make_iwid_property(attr):
+        def getter(self):
+            if getattr(self, attr, None) is None:
+                self.load_IWID()
+            return getattr(self, attr)
+        return property(getter)
+    iwid = make_iwid_property("_iwid")
+    iwid_full = make_iwid_property("_iwid_full")
 
     def load_IWID(self):
         """ Loads the InterWikiID of this instance. It is used to identify the instance
             globally.
             The IWID is available as cfg.iwid
             The full IWID containing the interwiki name is available as cfg.iwid_full
+            This method is called by the property.
         """
 
         try:
@@ -572,11 +588,11 @@
             self.meta_dict['IWID'] = iwid
             self.meta_dict.sync()
 
-        self.iwid = iwid
+        self._iwid = iwid
         if self.interwikiname is not None:
-            self.iwid_full = packLine([iwid, self.interwikiname])
+            self._iwid_full = packLine([iwid, self.interwikiname])
         else:
-            self.iwid_full = packLine([iwid])
+            self._iwid_full = packLine([iwid])
 
     def _config_check(self):
         """ Check namespace and warn about unknown names
--- a/docs/CHANGES.aschremmer	Mon Jul 31 11:20:22 2006 +0200
+++ b/docs/CHANGES.aschremmer	Mon Jul 31 12:01:57 2006 +0200
@@ -79,6 +79,7 @@
 Week 30: Implemented IWID support, added function to generate random strings. Added support
          for editing the InterWikiMap in the wiki. Added locking to the PickleTagStore and the MetaDict classes. Added handling of
          various options and detection of anonymous wikis to the SyncPages action.
+Week 31: Load the IWID and the meta dict lazily.
 
 2006-07-18: the requested daily entry is missing here, see http://moinmoin.wikiwikiweb.de/GoogleSoc2006/BetterProgress
 2006-07-19: the requested daily entry is missing here, see http://moinmoin.wikiwikiweb.de/GoogleSoc2006/BetterProgress