From e364bce7d1e9b60d647d5fe8ee98e1c9c37317ef Mon Sep 17 00:00:00 2001 From: louis Date: Sun, 25 Aug 2013 12:21:59 +0200 Subject: Implemented cache so that an already looked up series or movie will not be looked up again --- themoviedbscraper/themoviedbscraper.c | 12 +++++++++--- themoviedbscraper/themoviedbscraper.h | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) (limited to 'themoviedbscraper') diff --git a/themoviedbscraper/themoviedbscraper.c b/themoviedbscraper/themoviedbscraper.c index 8e33779..8dd05df 100644 --- a/themoviedbscraper/themoviedbscraper.c +++ b/themoviedbscraper/themoviedbscraper.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include "themoviedbscraper.h" @@ -94,10 +95,14 @@ bool cMovieDBScraper::parseJSON(string jsonString) { } int cMovieDBScraper::SearchMovie(string movieName) { - stringstream movieEscaped; - movieEscaped << "\"" << movieName << "\""; + map::iterator cacheHit = cache.find(movieName); + if (cacheHit != cache.end()) { + if (config.enableDebug) + esyslog("tvscraper: found cache %s => %d", ((string)cacheHit->first).c_str(), (int)cacheHit->second); + return (int)cacheHit->second; + } stringstream url; - url << baseURL << "/search/movie?api_key=" << apiKey << "&query=" << CurlEscape(movieEscaped.str().c_str()) << "&language=" << language.c_str(); + url << baseURL << "/search/movie?api_key=" << apiKey << "&query=" << CurlEscape(movieName.c_str()) << "&language=" << language.c_str(); if (config.enableDebug) esyslog("tvscraper: calling %s", url.str().c_str()); string movieJSON; @@ -107,6 +112,7 @@ int cMovieDBScraper::SearchMovie(string movieName) { movieID = movie->ParseJSONForMovieId(movieName); delete movie; } + cache.insert(pair(movieName, movieID)); return movieID; } diff --git a/themoviedbscraper/themoviedbscraper.h b/themoviedbscraper/themoviedbscraper.h index 54d463b..3560fb5 100644 --- a/themoviedbscraper/themoviedbscraper.h +++ b/themoviedbscraper/themoviedbscraper.h @@ -16,6 +16,7 @@ private: string backdropSize; string actorthumbSize; cTVScraperDB *db; + map cache; bool parseJSON(string jsonString); int SearchMovie(string movieName); cMovieDbMovie *ReadMovie(int movieID); -- cgit v1.2.3