optimize history saving

Only save the history if we really added an item. The saving is skipped, if
the item is already present in the model->items list.
2 jobs for !1 with master in 1 minute and 12 seconds
merge request