Re: [Zope] Problems with list of object references
Hello Max,
Then I would probably create a list of the 100 most recent articles. You can create a product that holds a single list "latestNews".
This is what I'm currently doing, as you can see in my initial posting.
Then have a method something like this to add the news items to:
def addDateItem(self, itm): news = self.latestNews news.append(news.getPhysicalPath()) if len(news) > 100: news.remove(100) self.latestNews = news
def getLatestNews(self): # converts paths to objects return [self.getPhysicalRoot().restrictedTraverse(path) for path in self.latestNews]
I do exactly the same in my buffer product, but with different code. The problem with this method is, that I have to call self.getPhysicalRoot().restrictedTraverse(path) 100 times every time I call getLatestNews, and this is to slow :-( I was thinking about your suggestion to use ZCatalog. Isn't the attribute data_record_id_ some kind of object reference? It seems to be unique and static. Do you now how it is generated? Greetings Sven -- Sven Rudolph, Programmierer GermanMedicalServices.de GmbH Unter den Eichen 5, 65195 Wiesbaden Tel.: 06 11 / 97 46 25 2
Sven Rudolph wrote:
def getLatestNews(self): # converts paths to objects return [self.getPhysicalRoot().restrictedTraverse(path) for path in self.latestNews]
I was thinking about your suggestion to use ZCatalog. Isn't the attribute data_record_id_ some kind of object reference? It seems to be unique and static. Do you now how it is generated?
My guess is that it is a key to an object in the ZCatalog, which then has the path stored :-/ The problem is that the only unique id for an object in Zope is the path. There is a global object id, but you cannot trust it. Ie. when an object is imported/exported it get weird. Or when you use another storage etc. You should really only store the nessecary metadata in the Catalog ie. just enough to view an object in a list. Do you really need the full object to be envoked/rendered in that 100 article list? regards Max M "klaatu verata niktu"
Hello Max,
I was thinking about your suggestion to use ZCatalog. Isn't the attribute data_record_id_ some kind of object reference? It seems to be unique and static. Do you now how it is generated?
My guess is that it is a key to an object in the ZCatalog, which then has the path stored :-/
All paths lead to restrictedTraverse... ;-) [...]
Do you really need the full object to be envoked/rendered in that 100 article list? I need this list for different purposes. In most cases I need access to object attributes. Currently my list is a path list, and I use it with: for path_to_object in object_paths: restrictedTraverse(path_to_object).my_object_attribute()
But I have tested it with a list of real object references: for item in object_references: item.my_object_attribute() This is much faster, but the list turns invalid after a few minutes (no restart, no refresh of the buffer product, just waiting). Zope caches objects after access. I think the objects in my object list are removed from the cache after a while, and when the above for loop uses the list again, the references point to nothing ... I'm afraid I have to live with this performance loss (using a path list), and give up at this point. Greetings Sven -- Sven Rudolph, Programmierer GermanMedicalServices.de GmbH Unter den Eichen 5, 65195 Wiesbaden Tel.: 06 11 / 97 46 25 2
participants (2)
-
Max M -
Sven Rudolph