diff --git a/lib/db_ido/dbevents.cpp b/lib/db_ido/dbevents.cpp index a0c5d5812..0da037c77 100644 --- a/lib/db_ido/dbevents.cpp +++ b/lib/db_ido/dbevents.cpp @@ -303,7 +303,12 @@ void DbEvents::EnableChangedHandlerInternal(const Checkable::Ptr& checkable, con /* comments */ void DbEvents::AddComments(const Checkable::Ptr& checkable) { - BOOST_FOREACH(const Comment::Ptr& comment, checkable->GetComments()) { + std::set comments = checkable->GetComments(); + + if (!comments.empty()) + RemoveComments(checkable); + + BOOST_FOREACH(const Comment::Ptr& comment, comments) { AddComment(comment); } } @@ -430,9 +435,12 @@ void DbEvents::RemoveComment(const Comment::Ptr& comment) /* downtimes */ void DbEvents::AddDowntimes(const Checkable::Ptr& checkable) { - RemoveDowntimes(checkable); + std::set downtimes = checkable->GetDowntimes(); - BOOST_FOREACH(const Downtime::Ptr& downtime, checkable->GetDowntimes()) { + if (!downtimes.empty()) + RemoveDowntimes(checkable); + + BOOST_FOREACH(const Downtime::Ptr& downtime, downtimes) { AddDowntime(downtime, false); } }