Skip to content

Instantly share code, notes, and snippets.

@epicmonkey
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save epicmonkey/6ae90583c3cba1d2d215 to your computer and use it in GitHub Desktop.
Save epicmonkey/6ae90583c3cba1d2d215 to your computer and use it in GitHub Desktop.
"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