lookupHits method

  1. @override
void lookupHits()
override

Implementation

@override
void lookupHits() async {
  // Load the hits in cache if exist
  visitor.config.hitCacheImp?.lookupHits().then((value) {
    // Convert hits map to list hit
    List<BaseHit> remainListOfTrackInCache =
        FlagshipTools.converMapToListOfHits(value);
    List<String> invalidIds = [];
    List<BaseHit> remainTracking = [];
    //Remove oldest hit
    remainListOfTrackInCache.forEach((element) {
      if (element.isLessThan4H()) {
        remainTracking.add(element);
      } else {
        invalidIds.add(element.id);
      }
    });
    // Add backed elements of tracking
    if (remainTracking.isNotEmpty) {
      Flagship.logger(Level.DEBUG,
          "Adding the founded hits and activate in cache to the pools");
      visitor.trackingManager?.addTrackingElementsToBatch(remainTracking);
    }
    // Remove invalide hits or activate
    if (invalidIds.isNotEmpty) {
      Flagship.logger(Level.INFO,
          "Some tracking found in cache are useless because their date of creation is more than 4 hours, the process will remove them");
      visitor.config.hitCacheImp?.flushHits(invalidIds);
    }
  }).timeout(
      Duration(
          milliseconds: visitor.config.hitCacheImp?.hitCacheLookupTimeout ??
              200), onTimeout: () {
    Flagship.logger(Level.ERROR, "Timeout on reading hits for cache");
  });
}