Give each PDBMixin an init and a cache. Not used yet
This commit is contained in:
		
							parent
							
								
									2ecf2e3d81
								
							
						
					
					
						commit
						55ed6a6d28
					
				
					 2 changed files with 32 additions and 0 deletions
				
			
		|  | @ -146,6 +146,11 @@ DEFAULT_DATADIR = '.\\_etiquette' | ||||||
| DEFAULT_CONFIGURATION = { | DEFAULT_CONFIGURATION = { | ||||||
|     'log_level': logging.DEBUG, |     'log_level': logging.DEBUG, | ||||||
| 
 | 
 | ||||||
|  |     'cache_size_album': 200, | ||||||
|  |     'cache_size_photo': 1000, | ||||||
|  |     'cache_size_tag': 1000, | ||||||
|  |     'cache_size_user': 200, | ||||||
|  | 
 | ||||||
|     'enable_new_album': True, |     'enable_new_album': True, | ||||||
|     'enable_new_bookmark': True, |     'enable_new_bookmark': True, | ||||||
|     'enable_new_photo': True, |     'enable_new_photo': True, | ||||||
|  |  | ||||||
|  | @ -16,6 +16,7 @@ from . import helpers | ||||||
| from . import objects | from . import objects | ||||||
| from . import searchhelpers | from . import searchhelpers | ||||||
| 
 | 
 | ||||||
|  | from voussoirkit import cacheclass | ||||||
| from voussoirkit import expressionmatch | from voussoirkit import expressionmatch | ||||||
| from voussoirkit import pathclass | from voussoirkit import pathclass | ||||||
| from voussoirkit import safeprint | from voussoirkit import safeprint | ||||||
|  | @ -252,6 +253,10 @@ def tag_export_totally_flat(tags): | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PDBAlbumMixin: | class PDBAlbumMixin: | ||||||
|  |     def __init__(self): | ||||||
|  |         super().__init__() | ||||||
|  |         self._album_cache = cacheclass.Cache() | ||||||
|  | 
 | ||||||
|     def get_album(self, id): |     def get_album(self, id): | ||||||
|         return self.get_thing_by_id('album', id) |         return self.get_thing_by_id('album', id) | ||||||
| 
 | 
 | ||||||
|  | @ -346,6 +351,9 @@ class PDBAlbumMixin: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PDBBookmarkMixin: | class PDBBookmarkMixin: | ||||||
|  |     def __init__(self): | ||||||
|  |         super().__init__() | ||||||
|  | 
 | ||||||
|     def get_bookmark(self, id): |     def get_bookmark(self, id): | ||||||
|         cur = self.sql.cursor() |         cur = self.sql.cursor() | ||||||
|         cur.execute('SELECT * FROM bookmarks WHERE id == ?', [id]) |         cur.execute('SELECT * FROM bookmarks WHERE id == ?', [id]) | ||||||
|  | @ -391,6 +399,10 @@ class PDBBookmarkMixin: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PDBPhotoMixin: | class PDBPhotoMixin: | ||||||
|  |     def __init__(self): | ||||||
|  |         super().__init__() | ||||||
|  |         self._photo_cache = cacheclass.Cache() | ||||||
|  | 
 | ||||||
|     def get_photo(self, photoid): |     def get_photo(self, photoid): | ||||||
|         return self.get_thing_by_id('photo', photoid) |         return self.get_thing_by_id('photo', photoid) | ||||||
| 
 | 
 | ||||||
|  | @ -880,6 +892,10 @@ class PDBPhotoMixin: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PDBTagMixin: | class PDBTagMixin: | ||||||
|  |     def __init__(self): | ||||||
|  |         super().__init__() | ||||||
|  |         self._tag_cache = cacheclass.Cache() | ||||||
|  | 
 | ||||||
|     def export_tags(self, exporter=tag_export_stdout, specific_tag=None): |     def export_tags(self, exporter=tag_export_stdout, specific_tag=None): | ||||||
|         ''' |         ''' | ||||||
|         Send the top-level tags to function `exporter`. |         Send the top-level tags to function `exporter`. | ||||||
|  | @ -986,6 +1002,10 @@ class PDBTagMixin: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class PDBUserMixin: | class PDBUserMixin: | ||||||
|  |     def __init__(self): | ||||||
|  |         super().__init__() | ||||||
|  |         self._user_cache = cacheclass.Cache() | ||||||
|  | 
 | ||||||
|     def generate_user_id(self): |     def generate_user_id(self): | ||||||
|         ''' |         ''' | ||||||
|         User IDs are randomized instead of integers like the other objects, |         User IDs are randomized instead of integers like the other objects, | ||||||
|  | @ -1118,6 +1138,8 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs | ||||||
|             self, |             self, | ||||||
|             data_directory=None, |             data_directory=None, | ||||||
|         ): |         ): | ||||||
|  |         super().__init__() | ||||||
|  | 
 | ||||||
|         if data_directory is None: |         if data_directory is None: | ||||||
|             data_directory = constants.DEFAULT_DATADIR |             data_directory = constants.DEFAULT_DATADIR | ||||||
| 
 | 
 | ||||||
|  | @ -1172,6 +1194,11 @@ class PhotoDB(PDBAlbumMixin, PDBBookmarkMixin, PDBPhotoMixin, PDBTagMixin, PDBUs | ||||||
|         self.on_commit_queue = [] |         self.on_commit_queue = [] | ||||||
|         self._cached_frozen_children = None |         self._cached_frozen_children = None | ||||||
| 
 | 
 | ||||||
|  |         self._album_cache.maxlen = self.config['cache_size_album'] | ||||||
|  |         self._photo_cache.maxlen = self.config['cache_size_photo'] | ||||||
|  |         self._tag_cache.maxlen = self.config['cache_size_tag'] | ||||||
|  |         self._user_cache.maxlen = self.config['cache_size_user'] | ||||||
|  | 
 | ||||||
|     def __repr__(self): |     def __repr__(self): | ||||||
|         return 'PhotoDB(data_directory={datadir})'.format(datadir=repr(self.data_directory)) |         return 'PhotoDB(data_directory={datadir})'.format(datadir=repr(self.data_directory)) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue