From 19d12c3132c8ca10adb77862d38d39caa4375aaa Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Tue, 27 Sep 2022 17:53:07 -0700 Subject: [PATCH] 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. --- etiquette/objects.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/etiquette/objects.py b/etiquette/objects.py index 7917bbb..0459f78 100644 --- a/etiquette/objects.py +++ b/etiquette/objects.py @@ -567,7 +567,7 @@ class Album(ObjectBase, GroupableMixin): ) return exists is not None - def jsonify(self, minimal=False) -> dict: + def jsonify(self, include_photos=True, minimal=False) -> dict: j = { 'type': 'album', 'id': self.id, @@ -579,9 +579,11 @@ class Album(ObjectBase, GroupableMixin): 'author': self.author.jsonify() if self._author_id else None, } if not minimal: - j['parents'] = [parent.jsonify(minimal=True) for parent in self.get_parents()] - j['children'] = [child.jsonify(minimal=True) for child in self.get_children()] - j['photos'] = [photo.jsonify(include_albums=False) for photo in self.get_photos()] + j['parents'] = [parent.id for parent in self.get_parents()] + j['children'] = [child.id for child in self.get_children()] + + if include_photos: + j['photos'] = [photo.id for photo in self.get_photos()] return j @@ -1170,7 +1172,7 @@ class Photo(ObjectBase): 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 = { 'type': 'photo', 'id': self.id, @@ -1191,11 +1193,13 @@ class Photo(ObjectBase): 'searchhidden': bool(self.searchhidden), 'simple_mimetype': self.simple_mimetype, } - if include_albums: - j['albums'] = [album.jsonify(minimal=True) for album in self.get_containing_albums()] - if include_tags: - j['tags'] = [tag.jsonify(minimal=True) for tag in self.get_tags()] + if not minimal: + if include_albums: + j['albums'] = [album.id for album in self.get_containing_albums()] + + if include_tags: + j['tags'] = [tag.id for tag in self.get_tags()] return j @@ -1779,11 +1783,11 @@ class Tag(ObjectBase, GroupableMixin): if not minimal: j['author'] = self.author.jsonify() if self._author_id else None j['description'] = self.description - j['parents'] = [parent.jsonify(minimal=True) for parent in self.get_parents()] - j['children'] = [child.jsonify(minimal=True) for child in self.get_children()] + j['parents'] = [parent.id for parent in self.get_parents()] + j['children'] = [child.id for child in self.get_children()] - if include_synonyms: - j['synonyms'] = list(self.get_synonyms()) + if include_synonyms: + j['synonyms'] = list(self.get_synonyms()) return j