Search code examples
pythondjangodjango-modelssolrdjango-haystack

Optimize displaying results with django-haystack RealTimeSignalProcessor


I use Django as backend for my web-app and django-haystack(with Solr) for searching & displaying results. I use the RealTimeSignalProccessor form django-haystack , but I have one problem:
- I have an Auction model and expires-(DateTimeField). When I'm displaying the results I'm doing it similar like e-bay (ex. Expires in: 1h 23m 5s ).
The problem is that on the page that all Auctions are displayed, if you want to update the Expires in parameter on every time you visit this view (as I've read in the django-haystack documentation) , you'll have to use the object.save() method to update the Solr indexing database. But if I do that for 30 results everytime i go to that view where all auctions are listed , it's very slow and it's not efficient.
Is there any other solution ? What do you suggest ?


Solution

  • There is no need to keep updating a expires_in field in your database - keep an expires_at with the time when the ad expires, and calculate the time left in your retrieval method in your model or in your view.

    This way you'll avoid having to write more data to your database as traffic increases, and if the expiry date changes you won't run into a possible race condition if people are viewing the page at the same time while you're updating the expiry time.