Fix updated_at in media_metadata_cache

This commit is contained in:
Calvin Montgomery 2020-03-20 19:44:11 -07:00
parent 5a386d0f81
commit 83fd8f11b2
2 changed files with 3 additions and 8 deletions

View File

@ -1,5 +1,4 @@
import { createMySQLDuplicateKeyUpdate } from '../util/on-duplicate-key-update'; import { createMySQLDuplicateKeyUpdate } from '../util/on-duplicate-key-update';
const Switches = require('../switches');
const Media = require('cytube-mediaquery/lib/media'); const Media = require('cytube-mediaquery/lib/media');
@ -28,8 +27,6 @@ class MetadataCacheDB {
} }
async put(media) { async put(media) {
if (!Switches.isActive('ytCache')) return;
media = new Media(media); media = new Media(media);
media.type = mediaquery2cytube(media.type); media.type = mediaquery2cytube(media.type);
return this.db.runTransaction(async tx => { return this.db.runTransaction(async tx => {
@ -37,10 +34,11 @@ class MetadataCacheDB {
.insert({ .insert({
id: media.id, id: media.id,
type: media.type, type: media.type,
metadata: JSON.stringify(media) metadata: JSON.stringify(media),
updated_at: tx.raw('CURRENT_TIMESTAMP')
}); });
let update = tx.raw(createMySQLDuplicateKeyUpdate( let update = tx.raw(createMySQLDuplicateKeyUpdate(
['metadata'] ['metadata', 'updated_at']
)); ));
return tx.raw(insert.toString() + update.toString()); return tx.raw(insert.toString() + update.toString());
@ -48,8 +46,6 @@ class MetadataCacheDB {
} }
async get(id, type) { async get(id, type) {
if (!Switches.isActive('ytCache')) return null;
return this.db.runTransaction(async tx => { return this.db.runTransaction(async tx => {
let row = await tx.table('media_metadata_cache') let row = await tx.table('media_metadata_cache')
.where({ id, type }) .where({ id, type })

View File

@ -1,5 +1,4 @@
const switches = { const switches = {
ytCache: true
}; };
export function isActive(switchName) { export function isActive(switchName) {