Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Tracker DB v4 endpoints #616

Merged
merged 10 commits into from Jan 5, 2021
Next

migrate to tracker db v4

  • Loading branch information
christophertino committed Oct 5, 2020
commit b767c81eb5b09813ad75e3523fe8e736ee9443f3
@@ -8,5 +8,5 @@
"aid": 6
}
],
"click2playVersion": 0
"version": 0
}
@@ -8,5 +8,5 @@
]
}
],
"compatibilityVersion": 0
"version": 0
}
@@ -2,13 +2,11 @@
"surrogates": {
"1": "var urchinTracker=function(){},_gaq={push:function(){try {if(arguments[0][0]==='_link'){window.location.href=arguments[0][1];}}catch(er){}}},_gat={_createTracker:function(){}, _getTracker:function(){return{__noSuchMethod__:function(){},_link:function(o){if(o){location.href=o;}},_linkByPost:function(){return true;},_getLinkerUrl:function(o){return o;},_trackEvent:function(){}};}};"
},

"mappings": [
{
"app_id": [13],
"sid": 1
}
],

"version": 0
}
@@ -70,7 +70,7 @@ const {
const IS_EDGE = (BROWSER_INFO.name === 'edge');
const IS_FIREFOX = (BROWSER_INFO.name === 'firefox');
const IS_ANDROID = (BROWSER_INFO.os === 'android');
const VERSION_CHECK_URL = `${CDN_BASE_URL}/update/version`;
const VERSION_CHECK_URL = `${CDN_BASE_URL}/update/v4/version`;
const REAL_ESTATE_ID = 'ghostery';
const ONE_DAY_MSEC = 86400000;
const ONE_HOUR_MSEC = 3600000;
@@ -120,9 +120,9 @@ function updateDBs() {
utils.getJson(VERSION_CHECK_URL).then((data) => {
log('Database version retrieval succeeded', data);

c2pDb.update(data.click2playVersion);
compDb.update(data.compatibilityVersion);
bugDb.update(data.bugsVersion, (result) => {
c2pDb.update(data.click2play);
compDb.update(data.compatibility);
bugDb.update(data.bugs, (result) => {
log('CHECK LIBRARY VERSION CALLED', result);
if (result.success) {
const nowTime = Number(new Date().getTime());
@@ -12,7 +12,7 @@
*/

import {
difference, each, every, keys, reduce, size
difference, each, every, keys, size
} from 'underscore';
import conf from './Conf';
import Updatable from './Updatable';
@@ -194,34 +194,13 @@ class BugDb extends Updatable {
if (!fromMemory) {
const old_bugs = conf.bugs;
let new_app_ids;
// if there is an older bugs object in storage,
// update newAppIds and apply block-by-default
if (old_bugs) {
if (old_bugs.hasOwnProperty('version') && bugs.version > old_bugs.version) {
new_app_ids = BugDb.updateNewAppIds(bugs.apps, old_bugs.apps);

if (new_app_ids.length) {
BugDb.applyBlockByDefault(new_app_ids);
db.JUST_UPDATED_WITH_NEW_TRACKERS = true;
}

// pre-trie/legacy db
} else if (old_bugs.hasOwnProperty('bugsVersion') && bugs.version !== old_bugs.bugsVersion) {
const old_apps = reduce(old_bugs.bugs, (acc, bug) => {
acc[bug.aid] = true;
return acc;
}, {});

new_app_ids = BugDb.updateNewAppIds(bugs.apps, old_apps);

if (new_app_ids.length) {
BugDb.applyBlockByDefault(new_app_ids);

// don't claim new trackers when db got downgraded by version
if (bugs.version > old_bugs.bugsVersion) {
db.JUST_UPDATED_WITH_NEW_TRACKERS = true;
}
}
// if there is an older bugs object in storage update newAppIds and apply block-by-default
if (old_bugs && old_bugs.hasOwnProperty('version') && (old_bugs.version !== bugs.version)) {
new_app_ids = BugDb.updateNewAppIds(bugs.apps, old_bugs.apps);

if (new_app_ids.length) {
BugDb.applyBlockByDefault(new_app_ids);
db.JUST_UPDATED_WITH_NEW_TRACKERS = true;
}
}

@@ -41,7 +41,7 @@ class Click2PlayDb extends Updatable {
log('processing c2p...');

try {
db = Click2PlayDb._buildDb(data.click2play, data.click2playVersion);
db = Click2PlayDb._buildDb(data.click2play, data.version);
} catch (e) {
log('Click2PlayDb processList() error', e);
return false;
@@ -36,7 +36,7 @@ class CompatibilityDb extends Updatable {
log('processing comp...');

try {
db = CompatibilityDb._buildDb(comp.compatibility, comp.compatibilityVersion);
db = CompatibilityDb._buildDb(comp.compatibility, comp.version);
} catch (e) {
log('CompatibilityDb processList() error', e);
return false;
@@ -74,10 +74,9 @@ class Updatable {
_localFetcher() {
return new Promise((resolve, reject) => {
const memory = conf[this.type];
const version_property = (this.type === 'bugs' || this.type === 'surrogates' ? 'version' : (`${this.type}Version`));

// nothing in storage, or it's so old it doesn't have a version
if (!memory || !memory.hasOwnProperty(version_property)) {
if (!memory || !memory.hasOwnProperty('version')) {
// return what's on disk
log(`fetching ${this.type} from disk`);

@@ -94,7 +93,7 @@ class Updatable {
} else if (this.just_upgraded) {
// on upgrades, see if json shipped w/ the extension is more recent
fetchLocalJSONResource(`databases/${this.type}.json`).then((disk) => {
if (disk[version_property] > memory[version_property]) {
if (disk.version !== memory.version) {
log(`fetching updated${this.type} from disk`);
resolve({
fromMemory: false,
@@ -131,8 +130,7 @@ class Updatable {
*/
_remoteFetcher(callback) {
log(`fetching ${this.type} from remote`);
const UPDATE_URL = `${CDN_BASE_URL}/update/${
this.type === 'bugs' ? 'v3/bugs' : this.type}`;
const UPDATE_URL = `${CDN_BASE_URL}/update/v4/${this.type}`;

getJson(UPDATE_URL).then((list) => {
callback(true, list);
@@ -153,7 +151,7 @@ class Updatable {
log('LOCAL VERSION, SERVER VERSION', this.db.version, options.version);

// is the local version already up-to-date?
if (this.db.version && options.version && (options.version <= this.db.version)) {
if (this.db.version && options.version && (options.version === this.db.version)) {
if (options.callback) {
options.callback({
success: true,
@@ -110,10 +110,10 @@ cat ${TMP_FILE} > $VERSION_FILE # copy into manifest.json
rm -f ${TMP_FILE}

# Download databases
curl "https://cdn.ghostery.com/update/v3/bugs" -o $DB_DIR/bugs.json --compressed --fail
curl "https://cdn.ghostery.com/update/click2play" -o $DB_DIR/click2play.json --compressed --fail
curl "https://cdn.ghostery.com/update/compatibility" -o $DB_DIR/compatibility.json --compressed --fail
curl "https://cdn.ghostery.com/update/surrogates" -o $DB_DIR/surrogates.json --compressed --fail
curl "https://cdn.ghostery.com/update/v4/bugs" -o $DB_DIR/bugs.json --compressed --fail
curl "https://cdn.ghostery.com/update/v4/click2play" -o $DB_DIR/click2play.json --compressed --fail
curl "https://cdn.ghostery.com/update/v4/compatibility" -o $DB_DIR/compatibility.json --compressed --fail
curl "https://cdn.ghostery.com/update/v4/surrogates" -o $DB_DIR/surrogates.json --compressed --fail

# Zip final build files
echo "Zipping to $(pwd)/$BUILD_DIR/"
ProTip! Use n and p to navigate between commits in a pull request.