mirror of https://github.com/calzoneman/sync.git
Enable caching BitChute metadata
This commit is contained in:
parent
25ddc336e0
commit
97b8d1b4b7
|
@ -85,6 +85,9 @@ module.exports.init = function (newDB) {
|
||||||
require('@cytube/mediaquery/lib/provider/youtube').setCache(
|
require('@cytube/mediaquery/lib/provider/youtube').setCache(
|
||||||
new MetadataCacheDB(db)
|
new MetadataCacheDB(db)
|
||||||
);
|
);
|
||||||
|
require('@cytube/mediaquery/lib/provider/bitchute').setCache(
|
||||||
|
new MetadataCacheDB(db)
|
||||||
|
);
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
LOGGER.error(error.stack);
|
LOGGER.error(error.stack);
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
|
|
|
@ -9,6 +9,8 @@ function mediaquery2cytube(type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'youtube':
|
case 'youtube':
|
||||||
return 'yt';
|
return 'yt';
|
||||||
|
case 'bitchute':
|
||||||
|
return 'bc';
|
||||||
default:
|
default:
|
||||||
throw new Error(`mediaquery2cytube: no mapping for ${type}`);
|
throw new Error(`mediaquery2cytube: no mapping for ${type}`);
|
||||||
}
|
}
|
||||||
|
@ -18,14 +20,17 @@ function cytube2mediaquery(type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case 'yt':
|
case 'yt':
|
||||||
return 'youtube';
|
return 'youtube';
|
||||||
|
case 'bc':
|
||||||
|
return 'bitchute';
|
||||||
default:
|
default:
|
||||||
throw new Error(`cytube2mediaquery: no mapping for ${type}`);
|
throw new Error(`cytube2mediaquery: no mapping for ${type}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cachedResultAge = new Summary({
|
const cachedResultAge = new Summary({
|
||||||
name: 'cytube_yt_cache_result_age_seconds',
|
name: 'cytube_media_cache_result_age_seconds',
|
||||||
help: 'Age (in seconds) of cached record'
|
help: 'Age (in seconds) of cached record',
|
||||||
|
labelNames: ['source']
|
||||||
});
|
});
|
||||||
|
|
||||||
class MetadataCacheDB {
|
class MetadataCacheDB {
|
||||||
|
@ -62,10 +67,11 @@ class MetadataCacheDB {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let age = 0;
|
||||||
try {
|
try {
|
||||||
let age = (Date.now() - row.updated_at.getTime())/1000;
|
age = (Date.now() - row.updated_at.getTime())/1000;
|
||||||
if (age > 0) {
|
if (age > 0) {
|
||||||
cachedResultAge.observe(age);
|
cachedResultAge.labels(type).observe(age);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
LOGGER.error('Failed to record cachedResultAge metric: %s', error.stack);
|
LOGGER.error('Failed to record cachedResultAge metric: %s', error.stack);
|
||||||
|
@ -73,6 +79,7 @@ class MetadataCacheDB {
|
||||||
|
|
||||||
let metadata = JSON.parse(row.metadata);
|
let metadata = JSON.parse(row.metadata);
|
||||||
metadata.type = cytube2mediaquery(metadata.type);
|
metadata.type = cytube2mediaquery(metadata.type);
|
||||||
|
metadata.meta.cacheAge = age;
|
||||||
return new Media(metadata);
|
return new Media(metadata);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue