From 4ed9e079ae27aa9c822468a4c6e23ee2954e356e Mon Sep 17 00:00:00 2001 From: seife Date: Sun, 17 Apr 2011 17:36:53 +0000 Subject: [PATCH] sectionsd: avoid duplicate events When adding a new event remove others with the same start time and the same service id, but possibly different event id. This reduces the number of duplicates significantly, and is basically similar to what other projects are doing for this case. Due to the significant overhead this needs to be explicitly enabled by exporting the TEST_ADDEVENT environment variable before starting neutrino for now. Please test and report your findings to the mailing list. git-svn-id: file:///home/bas/coolstream_public_svn/THIRDPARTY/applications/neutrino-experimental@1410 e54a6e83-5905-42d5-8d5c-058d10e6a962 --- src/sectionsd/sectionsd.cpp | 56 +++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/src/sectionsd/sectionsd.cpp b/src/sectionsd/sectionsd.cpp index 382cb82d2..14d910f93 100644 --- a/src/sectionsd/sectionsd.cpp +++ b/src/sectionsd/sectionsd.cpp @@ -245,6 +245,8 @@ unsigned int privatePid=0; #endif int sectionsd_stop = 0; +static bool slow_addevent = false; + inline void readLockServices(void) { pthread_rwlock_rdlock(&servicesLock); @@ -896,9 +898,59 @@ static void addEvent(const SIevent &evt, const unsigned table_id, const time_t z (SIlanguage::getMode() == CSectionsdClient::LANGUAGE_MODE_OFF) && (zeit != 0)) e->setExtendedText("OFF",""); +/* + * this is test code, so indentation is deliberately wrong :-) + * we'll hopefully remove this if clause after testing is done + */ +if (slow_addevent) +{ + std::vector to_delete; + event_id_t e_key = e->uniqueKey(); + t_channel_id e_chid = e->get_channel_id(); + time_t start_time = e->times.begin()->startzeit; + bool found = false; + /* experiments have shown that iterating backwards here is much faster */ + MySIeventsOrderServiceUniqueKeyFirstStartTimeEventUniqueKey::iterator x = + mySIeventsOrderServiceUniqueKeyFirstStartTimeEventUniqueKey.end(); + + while (x != mySIeventsOrderServiceUniqueKeyFirstStartTimeEventUniqueKey.begin()) + { + x--; + if ((*x)->get_channel_id() != e_chid) + { + /* sorted by service id first */ + if (found) + break; + } + else + { + event_id_t x_key = (*x)->uniqueKey(); + found = true; + /* do we need this check? */ + if (x_key == e_key) + continue; + if ((*x)->table_id < e->table_id) + continue; + if ((*x)->times.begin()->startzeit != start_time) + continue; + + dprintf("%s: delete 0x%016llx.%02x time = 0x%016llx.%02x\n", __func__, + x_key, (*x)->table_id, e_key, e->table_id); + to_delete.push_back(x_key); + } + } + unlockEvents(); + + while (! to_delete.empty()) + { + deleteEvent(to_delete.back()); + to_delete.pop_back(); + } +} else { // Damit in den nicht nach Event-ID sortierten Mengen // Mehrere Events mit gleicher ID sind, diese vorher loeschen unlockEvents(); +} deleteEvent(e->uniqueKey()); readLockEvents(); if (mySIeventsOrderUniqueKey.size() >= max_events) { @@ -8654,6 +8706,10 @@ void sectionsd_main_thread(void */*data*/) struct sched_param parm; printf("$Id: sectionsd.cpp,v 1.305 2009/07/30 12:41:39 seife Exp $\n"); + /* "export TEST_ADDEVENT=true" to enable this */ + slow_addevent = (getenv("TEST_ADDEVENT") != NULL); + if (slow_addevent) + printf("====================> USING SLOW ADDEVENT <=========================\n"); SIlanguage::loadLanguages();