Hi Kaitlin,
On 17/03/11 00:22, Kaitlin Rupert wrote:
I've pushed the changes to a remote branch if you want to take a look:
http://meego.gitorious.org/meego-handset-ux/libseaside/commits/async.
I've taken a look through, and while the aim is good, I do see one
problem with this design.
you appear to be storing single instances of many different requests
(QContactSaveRequest instances for updateAvatar, updateContact, etc)
inside SeasideSyncModel. I'm not sure what your reasons are, but at the
least, this won't work as you expect with many requests being processed
at once.
this is because setContact while a request is still running is probably
not a good idea, and at best, start() on an already-running request is
going to return false. So when you have high contention with multiple
running saves, bad things will happen.
A better option is to abstract your saving of details of contacts to
have an explicit 'commit' functionality somehow, which might look
something like this for saving contacts:-
void SeasideSyncModel::savePendingContacts()
{
QContactLocalId id = priv->uuidToId[uuid];
QContact *contact = priv->idToContact[id];
if (!contact)
return;
QContactSaveRequest *saveRequest = new QContactSaveRequest(this);
connect(saveRequest,
SIGNAL(stateChanged(QContactAbstractRequest::State),
SLOT(onSaveStateChanged(QContactAbstractRequest::State));
saveRequest->setContacts(priv->unsavedContacts);
priv->unsavedContacts.clear();
if (!saveRequest->start()) {
qDebug() << Q_FUNC_INFO << "Save request failed to start";
delete saveRequest;
}
}
void SeasideSyncModel::onSaveStateChanged(QContactAbstractRequest::State
state)
{
// delete request if it's finished
// log error if it failed for some reason
}
... and then, presuming that savePendingContacts is a slot, you could
invoke it on a timer set to persist, say, 50-100ms after the last
alteration of data. In addition, this approach also allows you to easily
thread the save request to really prevent UI blocking, should you wish.
If you'd like, I can work on a patch prototyping this approach sometime
in the next day or two.
-Kaitlin
Best regards,
--
Robin Burchell
http://rburchell.com
_______________________________________________
MeeGo-dev mailing list
MeeGo-dev@meego.com
http://lists.meego.com/listinfo/meego-dev
http://wiki.meego.com/Mailing_list_guidelines