Jsonify child objects will be ids only, not more json.
Because albums and tags have both parents and children, there's quite a lot of redundant json when rendering each as a dict. I'd rather improve the bulk searchability of objects by their ids than bloat every response with redundant renderings of the same child objects. Also, all include_* parameters are now nested inside the minimal check so that minimal will take priority.
This commit is contained in:
		
							parent
							
								
									e9076c02f8
								
							
						
					
					
						commit
						19d12c3132
					
				
					 1 changed files with 17 additions and 13 deletions
				
			
		|  | @ -567,7 +567,7 @@ class Album(ObjectBase, GroupableMixin): | ||||||
|         ) |         ) | ||||||
|         return exists is not None |         return exists is not None | ||||||
| 
 | 
 | ||||||
|     def jsonify(self, minimal=False) -> dict: |     def jsonify(self, include_photos=True, minimal=False) -> dict: | ||||||
|         j = { |         j = { | ||||||
|             'type': 'album', |             'type': 'album', | ||||||
|             'id': self.id, |             'id': self.id, | ||||||
|  | @ -579,9 +579,11 @@ class Album(ObjectBase, GroupableMixin): | ||||||
|             'author': self.author.jsonify() if self._author_id else None, |             'author': self.author.jsonify() if self._author_id else None, | ||||||
|         } |         } | ||||||
|         if not minimal: |         if not minimal: | ||||||
|             j['parents'] = [parent.jsonify(minimal=True) for parent in self.get_parents()] |             j['parents'] = [parent.id for parent in self.get_parents()] | ||||||
|             j['children'] = [child.jsonify(minimal=True) for child in self.get_children()] |             j['children'] = [child.id for child in self.get_children()] | ||||||
|             j['photos'] = [photo.jsonify(include_albums=False) for photo in self.get_photos()] | 
 | ||||||
|  |             if include_photos: | ||||||
|  |                 j['photos'] = [photo.id for photo in self.get_photos()] | ||||||
| 
 | 
 | ||||||
|         return j |         return j | ||||||
| 
 | 
 | ||||||
|  | @ -1170,7 +1172,7 @@ class Photo(ObjectBase): | ||||||
| 
 | 
 | ||||||
|         return tag_by_id[tag_id] |         return tag_by_id[tag_id] | ||||||
| 
 | 
 | ||||||
|     def jsonify(self, include_albums=True, include_tags=True) -> dict: |     def jsonify(self, include_albums=True, include_tags=True, minimal=False) -> dict: | ||||||
|         j = { |         j = { | ||||||
|             'type': 'photo', |             'type': 'photo', | ||||||
|             'id': self.id, |             'id': self.id, | ||||||
|  | @ -1191,11 +1193,13 @@ class Photo(ObjectBase): | ||||||
|             'searchhidden': bool(self.searchhidden), |             'searchhidden': bool(self.searchhidden), | ||||||
|             'simple_mimetype': self.simple_mimetype, |             'simple_mimetype': self.simple_mimetype, | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         if not minimal: | ||||||
|             if include_albums: |             if include_albums: | ||||||
|             j['albums'] = [album.jsonify(minimal=True) for album in self.get_containing_albums()] |                 j['albums'] = [album.id for album in self.get_containing_albums()] | ||||||
| 
 | 
 | ||||||
|             if include_tags: |             if include_tags: | ||||||
|             j['tags'] = [tag.jsonify(minimal=True) for tag in self.get_tags()] |                 j['tags'] = [tag.id for tag in self.get_tags()] | ||||||
| 
 | 
 | ||||||
|         return j |         return j | ||||||
| 
 | 
 | ||||||
|  | @ -1779,8 +1783,8 @@ class Tag(ObjectBase, GroupableMixin): | ||||||
|         if not minimal: |         if not minimal: | ||||||
|             j['author'] = self.author.jsonify() if self._author_id else None |             j['author'] = self.author.jsonify() if self._author_id else None | ||||||
|             j['description'] = self.description |             j['description'] = self.description | ||||||
|             j['parents'] = [parent.jsonify(minimal=True) for parent in self.get_parents()] |             j['parents'] = [parent.id for parent in self.get_parents()] | ||||||
|             j['children'] = [child.jsonify(minimal=True) for child in self.get_children()] |             j['children'] = [child.id for child in self.get_children()] | ||||||
| 
 | 
 | ||||||
|             if include_synonyms: |             if include_synonyms: | ||||||
|                 j['synonyms'] = list(self.get_synonyms()) |                 j['synonyms'] = list(self.get_synonyms()) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue