I am storing the files in the uploads folder.  I've tried creating an index 
based on the filename and it doesn't appear to markedly improve the 
situation.

Upon further investigation, it seems to be more a problem with our 
server--or just internet routing--than anything else.  I'm measuring the 
time using Firefox's web console log and just watching the download times.  
The download times are rather random.  Sometimes its down to 400 ms, 
sometimes its almost 2000 ms, even for some of the static images.  

-Jim

On Monday, October 8, 2012 10:17:43 AM UTC-5, Niphlod wrote:
>
> the problem here is mainly that he's doing one query to retrieve the row. 
> then it's changing request.args to be able to call response.download (other 
> queries involved). That means that the query used to retrieve the filename 
> based on the custom key he's using is requiring and additional 800ms.
>
> Indexing the "filename" field is surely one thing to do (possibly also 
> with unique costraint).
> PS: are you using the static folder or you have the uploads saved into the 
> database itself ?
>
> Il giorno lunedì 8 ottobre 2012 16:12:36 UTC+2, Massimo Di Pierro ha 
> scritto:
>>
>> You are telling us that row = dbs.image(filename=name) takes 1200-400ms 
>> on your server. That is a lot.
>>
>> You should:
>> 1) try cache the requests
>>    row = 
>> dbs(dbs.image.filename=name).select(cache=(cache.ram,3600)).first()
>>    periodically you will need to clear cache to prevent leaks.
>> 2) create an index for image.filename 
>>
>> On Monday, 8 October 2012 05:10:13 UTC-5, Jim Gregory wrote:
>>>
>>>
>>> To optimize SEO, I prefer to use descriptive, keyword-rich image 
>>> filenames instead of the auto-generated names used by web2py. 
>>>
>>> Currently, I am using a custom download function that looks up the 
>>> auto-generated filename in a database using the original filename as a key, 
>>> then uses the standard download function to retrieve it. 
>>>
>>> def images():
>>>     name =  request.args(0)
>>>     row = dbs.image(filename=name)
>>>     if not row[file]:
>>>         raise HTTP(404)
>>>     else:
>>>         request.args.append(row[file])
>>>     return response.download(request,dbs)
>>>
>>> This will retrieve an image using <img 
>>> src="/images/descriptive-filename.jpg"> instead of <img 
>>> src="/download/tablename.fieldname.bf4662d6c87d9b7f.636f726e65722d627261636b6574732e6a7067.jpg>
>>>
>>> However, this takes 3 times longer on to retrieve an image on our server 
>>> (about 1200 ms vs 400 ms).
>>>
>>> Is there another way that is relatively simple that 1) is fast, 2) 
>>> wouldn't break the default admin, and 3) automatically delete old images 
>>> when an image is updated in the admin?
>>
>>

-- 



Reply via email to