On Mon, 2009-02-02 at 00:17 -0800, Julien Phalip wrote: > Hi, > > I'm a bit stuck with the design of a system and so I was wondering if > someone could give some advice. > > The system works as follows. Users can create documents, which are > stored in a Django model. To ensure there's no conflict, a document > can be modified only by one user at a time. > The edition of a document is made via a Flex application that > communicates with the server via Ajax. > When a user has finished modifying a document, the document is > released and another user can modify it. Finally, if a user wants to > open a document, but that document is currently being edited by > someone else, then the document would be opened in read-only mode, > until the lock is eventually released. > > So far, I'm planning to have something like this: > > class Document(models.Model): > content = models.CharField() > current_user = models.ForeignKey(User) > lock_timestamp = models.DateTimeField() > > As I see it, when the document is first opened, it is locked by > setting 'current_user' to request.user and 'lock_timestamp' to the > current time. Then, the frontend application keeps sending an ajax > request every 30 seconds to the remind the server that it is modifying > the document. So, the lock's timestamp is refreshed every 30 seconds > that the document is being used. When the frontend app is closed, the > timestamp is not refreshed any more, so if another user makes the > request at least 30 seconds later, the document will be released and > locked to him. > > Does that sound viable? Performance-wise, is that a good system? If > not, would you have any other approach to suggest?
I would make the lock objects separate from the document with a foreign-key from lock -> document. You might well want to change how locking is implemented over time and it's entirely unrelated to the concept of "document" (it's part of the concept of "document locking"). So don't prematurely denormalise. For example, you could then implement read-only locks of some sort if somebody wants to reserve the next writing slot for that document (which could be similarly expired). Or you could decide to change the locking strategy so that the writer has a 15 minute lock on writing, which is renewed whenever they hit "save" or until they release the lock (saying they're not editing any longer). That's how MoinMoinWiki does it, for example (with a slightly different implementation). If you did use that implementation strategy (or wanted to change to it later), you won't need to futz around with the "document" model/table, just the lock table. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---

