-
-
Save epicmonkey/6ae90583c3cba1d2d215 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
process.env.NODE_ENV = "development" | |
var run = async function() { | |
var express = require('express') | |
, app = express() | |
, environment = require('./config/environment') | |
, _ = require('lodash') | |
, mkKey = require("./app/support/models").mkKey | |
var app = await environment.init(app) | |
var redis = require('./config/database') | |
, database = redis.connect() | |
, models = require('./app/models') | |
var usernames = await database.keysAsync('username:*') | |
var userIds = await* usernames.map((username) => database.getAsync(username)) | |
var users = await* userIds.map((userId) => models.FeedFactory.findById(userId)) | |
var timelines = await* users.map((user) => user.getPostsTimeline()) | |
await* timelines.map(async function(timeline) { | |
let posts = await timeline.getPosts() | |
await* posts.map(async function(post) { | |
let postedTo = await post.getPostedToIds() | |
console.log('Checking post ' + post.id + '.') | |
if (postedTo.length === 0) { | |
let user = await models.User.findById(post.userId) | |
let key = await user.getPostsTimelineId() | |
let to = mkKey(["post", post.id, "to"]) | |
console.log('Need to set ' + to + ' to ' + key + '.') | |
await database.sadd(to, key) | |
console.log('Fixed.') | |
} else { | |
console.log('OK.') | |
} | |
}) | |
}) | |
console.log('Done.') | |
process.exit() | |
} | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment