Skip to content

Commit

Permalink
Fix updated_at in media_metadata_cache
Browse files Browse the repository at this point in the history
  • Loading branch information
calzoneman committed Mar 21, 2020
1 parent 5a386d0 commit 83fd8f1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
10 changes: 3 additions & 7 deletions src/database/metadata_cache.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { createMySQLDuplicateKeyUpdate } from '../util/on-duplicate-key-update';
const Switches = require('../switches');

const Media = require('cytube-mediaquery/lib/media');

Expand Down Expand Up @@ -28,28 +27,25 @@ class MetadataCacheDB {
}

async put(media) {
if (!Switches.isActive('ytCache')) return;

media = new Media(media);
media.type = mediaquery2cytube(media.type);
return this.db.runTransaction(async tx => {
let insert = tx.table('media_metadata_cache')
.insert({
id: media.id,
type: media.type,
metadata: JSON.stringify(media)
metadata: JSON.stringify(media),
updated_at: tx.raw('CURRENT_TIMESTAMP')
});
let update = tx.raw(createMySQLDuplicateKeyUpdate(
['metadata']
['metadata', 'updated_at']
));

return tx.raw(insert.toString() + update.toString());
});
}

async get(id, type) {
if (!Switches.isActive('ytCache')) return null;

return this.db.runTransaction(async tx => {
let row = await tx.table('media_metadata_cache')
.where({ id, type })
Expand Down
1 change: 0 additions & 1 deletion src/switches.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const switches = {
ytCache: true
};

export function isActive(switchName) {
Expand Down

0 comments on commit 83fd8f1

Please sign in to comment.