Skip to content

Commit

Permalink
ignore corrupt data in redis
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Feb 10, 2021
1 parent 12c8798 commit dedd435
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/migrations/001-activePlaylistState.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const { ObjectId } = require('mongoose').mongo;
const { zip } = require('lodash');

const rxObjectId = /^[0-9a-f]{24}$/;

async function up({ context: uw }) {
const { User } = uw.models;

Expand All @@ -15,6 +17,10 @@ async function up({ context: uw }) {
const values = await uw.redis.mget(keys);
for (const [key, playlistID] of zip(keys, values)) {
const userID = key.replace(/^playlist:/, '');
if (!rxObjectId.test(userID) || !rxObjectId.test(playlistID)) {
// must be corrupt if it isn't an object ID.
continue;
}

ops.push({
updateOne: {
Expand Down

0 comments on commit dedd435

Please sign in to comment.