{"action":"opened","issue":{"url":"https://api.github.com/repos/Moinax/TvDb/issues/21","labels_url":"https://api.github.com/repos/Moinax/TvDb/issues/21/labels{/name}","comments_url":"https://api.github.com/repos/Moinax/TvDb/issues/21/comments","events_url":"https://api.github.com/repos/Moinax/TvDb/issues/21/events","html_url":"https://github.com/Moinax/TvDb/issues/21","id":54313810,"number":21,"title":"Update Function - Logic and Documentation","user":{"login":"gittix09","id":4339303,"avatar_url":"https://avatars.githubusercontent.com/u/4339303?v=3","gravatar_id":"","url":"https://api.github.com/users/gittix09","html_url":"https://github.com/gittix09","followers_url":"https://api.github.com/users/gittix09/followers","following_url":"https://api.github.com/users/gittix09/following{/other_user}","gists_url":"https://api.github.com/users/gittix09/gists{/gist_id}","starred_url":"https://api.github.com/users/gittix09/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gittix09/subscriptions","organizations_url":"https://api.github.com/users/gittix09/orgs","repos_url":"https://api.github.com/users/gittix09/repos","events_url":"https://api.github.com/users/gittix09/events{/privacy}","received_events_url":"https://api.github.com/users/gittix09/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-14T11:52:26Z","updated_at":"2015-01-14T11:52:26Z","closed_at":null,"body":"First of all: great work!! Your API is extraordinary!!\r\nThere si only one thing I can't understand completely: which is the best way to use the $data[\"series\"] and $data[\"episodes\"] arrays that are returned by the function getUpdates($previousTime)?\r\n\r\nThis is the context:\r\nTwo tables in my local database (\"Series\" and \"Episodes\"). Each record in \"Episodes\" table has a \"thetvdb_episode_id\" field and a \"thetvdb_series_id\" field, that corresponds to the field \"thetvdb_id\" of table \"Series\". This way I know to which series the episodes belong.\r\n\r\nFinally, my database does NOT contain all the series/episodes that are present in the thetvdb database. Only the most popular ones, and I would like to keep it that way.\r\n\r\nWhat should I do now to update my database? Which is the best way (to minimize the number of requests to thetvdb and to my database)? Of course I only need to know the logic, not the actual code.\r\n\r\nThis is what I think:\r\n\r\nFIRST APPROACH:\r\n- cycle through the \"series\" array with a foreach\r\n- for each record, check if the series_id is present in my database (with a normal select query)\r\n- if so, request the series data to thetvdb and update my database\r\n\r\nFirst problem:\r\nwhen only an episode of a series is updated on thetvdb, will the series_id be present in $data[\"series\"] or does $data[\"series\"] reflect only the changes to the series details?\r\n\r\nSecond problem:\r\nNow I would be forced to replace all the series data in my database with the ones downloaded from thetvdb. That is of course wrong. There is no need to replace old/unchanged data along with the new ones. Maybe I could do a count and compare the the total episode or look at the \"lastUpdated\" field.\r\n\r\nSECOND APPROACH:\r\n- cycle through the \"episodes\" array with a foreach\r\n- for each record, request the episode data (including the series_id) to thetvdb\r\n- check if the series_id is present in my database (with a normal select query)\r\n- if so, add/update the episode data in my database\r\n\r\nProblem: almost 1000 request (one for each episode)... only 60 really useful.\r\n\r\nFINAL CONSIDERATION:\r\nEverything would be much easier if (in the $data[\"episodes\"] array) there was also a \"seriesId\" value for each episode. This way, I would cycle through the array, check if the seriesId is present in my database and (if so) retrive the episode data from thetvdb.  \r\n\r\n\r\n\r\n \r\n"}}