"J. Gleixner" <glex_no-> writes:
> On 03/30/12 08:05, Justin C wrote:
>> On 2012-03-29, J. Gleixner<glex_no-> wrote:
>>> On 03/28/12 10:24, Justin C wrote:
>>>> We have a database of thousands of clothing items. Some of the items are
>>>> almost identical apart from their size. Consequently we use the same
>>>> image in our web-shop to advertise items of the same style, design and
>>>> colour.
>>>> [...]
>>>> The bottle-neck, as I see it, is running grep 20k times, once for each
>>>> image found. Can anyone suggest a better way?
>>>
>>> Since you already have data in a DB, I'd suggest looking at
>>> associating these files, to the items, in the database.
>>>
>>> Maybe store the path to the file, or possibly the image as a BLOB, a
>>> many to one relationship.
>>
>> Unfortunately it's not a DB I'm authorised to write to. I can run
>> queries that extract data, but any changes to the data must be done
>> through the 3rd party supplied interface.
>
> OK. Then put it in your own database. MySQL, Postgres, SQLite, even a
> DBM file might work.
This is a 'simple' key <-> value mapping, only complicated by the fact
that keys can have multiple values associating with them. Provided
that the code for a particular stock item can be calculated, the
simple first attempt at a solution would still be to use a Perl hash
mapping codes to sets of stock item keys. This hash can be generated
once in advance and then be used for any number of 'fast' lookups. A
more elaborate design would be to use a flat-file hashed database ('DBM
file') to store the mappings, update that whenever the set of stock
items changes and use it to associate presently existing images with
stock items without recalculating the mappings. An even better idea
would be to use a persistent database mapping stock items to image
files and update this database whenever the set of image files
changes.
|