best way to implement Auto Save?

248 views
Skip to first unread message

devm...@hotmail.com

unread,
Jul 10, 2012, 1:19:39 AM7/10/12
to rav...@googlegroups.com
hi, 
i am thinking of implementing Auto save for articles feature, where if user forgets to save or in case of he lost connection or whatever, it is good when a user spent 1 hour creating an article an for example his computer went off,

if you could advise the bet way to do that in terms of performance and pattern with RavenDB.

my initial thinking is when user creates a new article, instead of waiting for him to save it when he press save, i would instead save it instantly when he hit the add new button, and then i mark the article as "AutoSave" and then he hits Save, i change the status to "Saved", what you guys think ?


devm...@hotmail.com

unread,
Jul 10, 2012, 1:20:35 AM7/10/12
to rav...@googlegroups.com
i forgot to ask, if this is right, what is the best way to clean old forgotten or orphan auto-saved articles?

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 1:20:30 AM7/10/12
to rav...@googlegroups.com
That would work, but how about if he want to UNsave?

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 1:22:18 AM7/10/12
to rav...@googlegroups.com
articles/1
articles/1/auto-save

That would be how I would go about doing this.

devm...@hotmail.com

unread,
Jul 10, 2012, 3:41:22 AM7/10/12
to rav...@googlegroups.com
thank you Ayende so much 
but what does this mean ? articles/1/auto-save 
is auto-save a property here ?

regarding unsave, that was my question, if he does not save and leave the page or for any other reason, the document will be still marked as unsaved, so the only way i am thinking about is to run some kind of process to query documents with unsaved status that are for example 1 day old, what do you think ?

Matt Warren

unread,
Jul 10, 2012, 3:54:51 AM7/10/12
to rav...@googlegroups.com
He means having 2 documents, with the following keys:

articles/1
articles/1/auto-save

That way you store the auto-save doc at "articles/1/auto-save" and if the user doesn't do undo, you copy the contents of that into "articles/1" which is the main version of the doc.

devm...@hotmail.com

unread,
Jul 10, 2012, 2:51:05 PM7/10/12
to rav...@googlegroups.com
thank you Itmar for clearing this up, but what is the best way to delete this  articles/1/auto-save  after it is orphan  in an automatic way?

as a side note, this is dumb but how can i create this kind of key?  articles/1/auto-save 

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 2:54:24 PM7/10/12
to rav...@googlegroups.com
session.Store(entity, "name");

Oren Eini (Ayende Rahien)

unread,
Jul 10, 2012, 2:54:34 PM7/10/12
to rav...@googlegroups.com
store.DatabaseCommands.Delete("name")

Chris Marisic

unread,
Jul 10, 2012, 2:55:02 PM7/10/12
to rav...@googlegroups.com


On Tuesday, July 10, 2012 2:51:05 PM UTC-4, devm...@hotmail.com wrote:
as a side note, this is dumb but how can i create this kind of key?  articles/1/auto-save 


 var obj = new Article { Id = "articles/1/auto-save" }

devm...@hotmail.com

unread,
Jul 10, 2012, 7:26:49 PM7/10/12
to rav...@googlegroups.com
thanks all i got it about the ID naming convention, 
but what about deleting those orphan docs in a scheduled way, that takes into account RavenDB Paging? should i a create background scheduler that runs and query all docs with UnSaved ID and delete them, or it is not good performance wise ?

Chris Marisic

unread,
Jul 10, 2012, 10:59:33 PM7/10/12
to rav...@googlegroups.com
I would recommend the expiration bundle and set the auto save documents to delete after say 10 days. If a user didn't want a draft of a blog post that they didn't even specifically save after 10 days, i'd think it'd be safe to delete it. Of course you could just easily do 30 days or 90 days etc.

Kijana Woodard

unread,
Jul 10, 2012, 11:05:46 PM7/10/12
to rav...@googlegroups.com
When they really save, just call delete on the auto save document.
You could show them a list of 'drafts', which they could choose to delete and you could auto expire as Chris mentioned.
For a doc thhat previously existed where they have an uncommitted auto save, you could ask them if they still want those changes like Office.

devm...@hotmail.com

unread,
Jul 10, 2012, 11:54:57 PM7/10/12
to rav...@googlegroups.com
Chris, that is awesome Advise i never thought of it, now this is a brilliant use of Expiration Bundle, thanks a lot.
Kijana, your advise is really great for giving a user more flexible options, thanks a lot man.

this place Rocks :)

Sean Kearon

unread,
Jul 11, 2012, 5:45:52 AM7/11/12
to rav...@googlegroups.com
Now, that is stupidly simple - just brilliant!!! :)

On Tuesday, July 10, 2012 6:22:18 AM UTC+1, Oren Eini wrote:
articles/1
articles/1/auto-save
Reply all
Reply to author
Forward
0 new messages