Ticket #12130: eitcache.cpp.diff

File eitcache.cpp.diff, 5.4 KB (added by klaas.de.waal@…, 10 years ago)

"git diff" of eitcache.cpp

  • mythtv/libs/libmythtv/eitcache.cpp

    diff --git a/mythtv/libs/libmythtv/eitcache.cpp b/mythtv/libs/libmythtv/eitcache.cpp
    index 79ec796..959b196 100644
    a b  
    1919const uint EITCache::kVersionMax = 31;
    2020
    2121EITCache::EITCache()
    22     : accessCnt(0), hitCnt(0),   tblChgCnt(0),   verChgCnt(0),
    23       entryCnt(0), pruneCnt(0), prunedHitCnt(0), wrongChannelHitCnt(0)
     22    : accessCnt(0), hitCnt(0), tblChgCnt(0), verChgCnt(0), endChgCnt(0),
     23      entryCnt(0), pruneCnt(0), prunedHitCnt(0), futureHitCnt(0), wrongChannelHitCnt(0)
    2424{
    2525    // 24 hours ago
    2626    lastPruneTime = MythDate::current().toUTC().toTime_t() - 86400;
    void EITCache::ResetStatistics(void) 
    3737    hitCnt    = 0;
    3838    tblChgCnt = 0;
    3939    verChgCnt = 0;
     40    endChgCnt = 0;
    4041    entryCnt  = 0;
    4142    pruneCnt  = 0;
    4243    prunedHitCnt = 0;
     44    futureHitCnt = 0;
    4345    wrongChannelHitCnt = 0;
    4446}
    4547
    QString EITCache::GetStatistics(void) const 
    4850    QMutexLocker locker(&eventMapLock);
    4951    return QString(
    5052        "EITCache::statistics: Accesses: %1, Hits: %2, "
    51         "Table Upgrades %3, New Versions: %4, Entries: %5 "
    52         "Pruned entries: %6, pruned Hits: %7 Discard channel Hit %8 "
    53         "Hit Ratio %9.")
    54         .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt)
    55         .arg(entryCnt).arg(pruneCnt).arg(prunedHitCnt)
     53        "Table Upgrades %3, New Versions: %4, New Endtimes: %5, Entries: %6, "
     54        "Pruned Entries: %7, Pruned Hits: %8, Future Hits: %9, Wrong Channel Hits %10, "
     55        "Hit Ratio %11.")
     56        .arg(accessCnt).arg(hitCnt).arg(tblChgCnt).arg(verChgCnt).arg(endChgCnt)
     57        .arg(entryCnt).arg(pruneCnt).arg(prunedHitCnt).arg(futureHitCnt)
    5658        .arg(wrongChannelHitCnt)
    57         .arg((hitCnt+prunedHitCnt+wrongChannelHitCnt)/(double)accessCnt);
     59        .arg((hitCnt+prunedHitCnt+futureHitCnt+wrongChannelHitCnt)/(double)accessCnt);
    5860}
    5961
    6062static inline uint64_t construct_sig(uint tableid, uint version,
    static void delete_in_db(uint endtime) 
    125127    return;
    126128}
    127129
     130
    128131#define EITDATA      0
    129132#define CHANNEL_LOCK 1
    130133#define STATISTIC    2
    131134
    132 static bool lock_channel(uint chanid, uint lastPruneTime)
     135static bool lock_channel(uint chanid, uint endtime)
    133136{
    134137    int lock = 1;
    135138    MSqlQuery query(MSqlQuery::InitCon());
    static bool lock_channel(uint chanid, uint lastPruneTime) 
    142145
    143146    query.prepare(qstr);
    144147    query.bindValue(":CHANID",   chanid);
    145     query.bindValue(":ENDTIME",  lastPruneTime);
     148    query.bindValue(":ENDTIME",  endtime);
    146149    query.bindValue(":STATUS",   CHANNEL_LOCK);
    147150
    148151    if (!query.exec() || !query.isActive())
    event_map_t * EITCache::LoadChannel(uint chanid) 
    235238    query.bindValue(":ENDTIME",  lastPruneTime);
    236239    query.bindValue(":STATUS",   EITDATA);
    237240
    238 
    239241    if (!query.exec() || !query.isActive())
    240242    {
    241243        MythDB::DBError("Error loading eitcache", query);
    void EITCache::WriteChannelToDB(uint chanid) 
    274276
    275277    uint size    = eventMap->size();
    276278    uint updated = 0;
     279    uint removed = 0;
    277280
    278281    event_map_t::iterator it = eventMap->begin();
    279282    while (it != eventMap->end())
    280283    {
    281         if (modified(*it) && extract_endtime(*it) > lastPruneTime)
     284        if (extract_endtime(*it) > lastPruneTime)
    282285        {
    283             replace_in_db(chanid, it.key(), *it);
    284             updated++;
    285             *it &= ~(uint64_t)0 >> 1; // mark as synced
     286            if (modified(*it))
     287            {
     288                replace_in_db(chanid, it.key(), *it);
     289                updated++;
     290                *it &= ~(uint64_t)0 >> 1; // mark as synced
     291            }
     292        }
     293        else
     294        {
     295            // Event is too old; remove from eit cache in memory
     296            eventMap->remove(it.key());
     297            removed++;
    286298        }
    287299        ++it;
    288300    }
    void EITCache::WriteChannelToDB(uint chanid) 
    292304        LOG(VB_EIT, LOG_INFO, LOC + QString("Wrote %1 modified entries of %2 "
    293305                                      "for channel %3 to database.")
    294306                .arg(updated).arg(size).arg(chanid));
     307    if (removed)
     308        LOG(VB_EIT, LOG_INFO, LOC + QString("Removed %1 old entries of %2 "
     309                                      "for channel %3 from cache.")
     310                .arg(removed).arg(size).arg(chanid));
     311    pruneCnt += removed;
    295312}
    296313
    297314void EITCache::WriteToDB(void)
    void EITCache::WriteToDB(void) 
    306323    }
    307324}
    308325
    309 
    310 
    311326bool EITCache::IsNewEIT(uint chanid,  uint tableid,   uint version,
    312327                        uint eventid, uint endtime)
    313328{
    bool EITCache::IsNewEIT(uint chanid, uint tableid, uint version, 
    319334        WriteToDB();
    320335    }
    321336
    322     // don't readd pruned entries
     337    // don't read pruned entries
    323338    if (endtime < lastPruneTime)
    324339    {
    325340        prunedHitCnt++;
    326341        return false;
    327342    }
     343
    328344    // validity check, reject events with endtime over 7 weeks in the future
    329345    if (endtime > lastPruneTime + 50 * 86400)
     346    {
     347        futureHitCnt++;
    330348        return false;
     349    }
    331350
    332351    QMutexLocker locker(&eventMapLock);
    333352    if (!channelMap.contains(chanid))
    bool EITCache::IsNewEIT(uint chanid, uint tableid, uint version, 
    358377            // EIT updated version on current table
    359378            verChgCnt++;
    360379        }
     380        else if (extract_endtime(*it) != endtime)
     381        {
     382            // Endtime (starttime + duration) changed
     383            endChgCnt++;
     384        }
    361385        else
    362386        {
    363387            // EIT data previously seen