Make Photo.bytestring a @property.

This is the kind of thing that should be a @property, because
it's very low processing power and doesn't hit the database.
This commit is contained in:
voussoir 2018-02-16 23:16:02 -08:00
parent bbe392ac09
commit b4a28f5034
4 changed files with 5 additions and 4 deletions

View file

@ -48,7 +48,7 @@ def photo(p, include_albums=True, include_tags=True):
'bytes': p.bytes, 'bytes': p.bytes,
'duration_str': p.duration_string, 'duration_str': p.duration_string,
'duration': p.duration, 'duration': p.duration,
'bytes_str': p.bytestring(), 'bytes_str': p.bytestring,
'has_thumbnail': bool(p.thumbnail), 'has_thumbnail': bool(p.thumbnail),
'created': p.created, 'created': p.created,
'filename': p.basename, 'filename': p.basename,

View file

@ -635,6 +635,7 @@ class Photo(ObjectBase):
self.photodb.commit() self.photodb.commit()
return tag return tag
@property
def bytestring(self): def bytestring(self):
if self.bytes is not None: if self.bytes is not None:
return bytestring.bytestring(self.bytes) return bytestring.bytestring(self.bytes)

View file

@ -192,7 +192,7 @@
<li>Dimensions: {{photo.width}}x{{photo.height}} px</li> <li>Dimensions: {{photo.width}}x{{photo.height}} px</li>
<li>Aspect ratio: {{photo.ratio}}</li> <li>Aspect ratio: {{photo.ratio}}</li>
{% endif %} {% endif %}
<li>Size: {{photo.bytestring()}}</li> <li>Size: {{photo.bytestring}}</li>
{% if photo.duration %} {% if photo.duration %}
<li>Duration: {{photo.duration_string}}</li> <li>Duration: {{photo.duration_string}}</li>
<li>Overall Bitrate: {{photo.bitrate|int}} kbps</li> <li>Overall Bitrate: {{photo.bitrate|int}} kbps</li>

View file

@ -20,7 +20,7 @@
<div class="photo_card photo_card_list" data-id="{{photo.id}}"> <div class="photo_card photo_card_list" data-id="{{photo.id}}">
<input type="checkbox" class="photo_card_selector_checkbox" onclick="on_photo_select(event)"/> <input type="checkbox" class="photo_card_selector_checkbox" onclick="on_photo_select(event)"/>
<span class="photo_card_filename"><a target="_blank" href="/photo/{{photo.id}}">{{photo.basename}}</a></span> <span class="photo_card_filename"><a target="_blank" href="/photo/{{photo.id}}">{{photo.basename}}</a></span>
<a class="photo_card_metadata" target="_blank" href="/file/{{photo.id}}.{{photo.extension}}">{{photo.bytestring()}}</a> <a class="photo_card_metadata" target="_blank" href="/file/{{photo.id}}.{{photo.extension}}">{{photo.bytestring}}</a>
</div> </div>
{% else %} {% else %}
@ -69,7 +69,7 @@
<span class="photo_card_metadata"> <span class="photo_card_metadata">
{{- metadata_inner|safe -}} {{- metadata_inner|safe -}}
<a target="_blank" href="/file/{{photo.id}}.{{photo.extension}}">{{photo.bytestring()}}</a> <a target="_blank" href="/file/{{photo.id}}.{{photo.extension}}">{{photo.bytestring}}</a>
</span> </span>
<input type="checkbox" class="photo_card_selector_checkbox" onclick="on_photo_select(event)"/> <input type="checkbox" class="photo_card_selector_checkbox" onclick="on_photo_select(event)"/>