lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-0.70.0.3 vs lib/fiona7/scrivito_patches/binary.rb in infopark_fiona7-0.71.0.0
- old
+ new
@@ -33,13 +33,19 @@
self.obj = self.load_obj
end
protected
attr_accessor :binary_id, :transformation, :obj
+ def cache(key, &block)
+ # TODO: make path this configurable
+ @@cache = ActiveSupport::Cache::FileStore.new(Rails.root + '/tmp/cache') unless defined?(@@cache)
+ @@cache.fetch("#{self.binary_id}-#{key}", &block)
+ end
+
def load_obj
if Fiona7.mode == :legacy
- Fiona7::WriteObj.find(self.binary_id)
+ Fiona7::EditedObj.find(self.binary_id)
else
Fiona7::InternalReleasedObj.find(self.binary_id)
end
rescue ActiveRecord::RecordNotFound
nil
@@ -66,23 +72,31 @@
def length
self.obj.body_length
end
def width
- if self.image
- self.image[:width]
- else
- 0
+ self.cache("#{self.last_changed}-width") do
+ if self.image
+ self.image[:width]
+ else
+ 0
+ end
end
+ rescue
+ 0
end
def height
- if self.image
- self.image[:height]
- else
- 0
+ self.cache("#{self.last_changed}-height") do
+ if self.image
+ self.image[:height]
+ else
+ 0
+ end
end
+ rescue
+ 0
end
def mime_type
self.obj.mime_type
end
@@ -410,11 +424,11 @@
protected
attr_writer :blob_id, :access_type, :verb, :transformation
def blob
if Fiona7.mode == :legacy
- @blob ||= Fiona7::WriteObj.find(blob_id.to_i)
+ @blob ||= Fiona7::EditedObj.find(blob_id.to_i)
else
@blob ||= Fiona7::InternalReleasedObj.find(blob_id.to_i)
end
end
@@ -457,10 +471,10 @@
token = ParamEncoder.new.encode(self.transformation)
return "t=#{token}"
end
def validate_transformation!
- MetaBinary.new(self.blob_id, self.transformation).valid? || raise(Scrivito::TransformationDefinitionError.new("Invalid transformation", "binary.unprocessable.image.transform.invalid_config"))
+ MetaBinary.new(self.blob_id, self.transformation).valid? || raise(Scrivito::TransformationDefinitionError.new("Invalid transformation", "binary.unprocessable.image.transform.config.invalid"))
end
end
end
end