Skip to content

Commit

Permalink
pushall green test
Browse files Browse the repository at this point in the history
  • Loading branch information
wiber committed Mar 24, 2015
1 parent c4b2584 commit 07adfd3
Show file tree
Hide file tree
Showing 4 changed files with 354 additions and 209 deletions.
85 changes: 48 additions & 37 deletions server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -67,68 +67,79 @@ modModifier.outbox = (modifier,userId) ->
feed: new Date().getTime()
]



modModifier.feed = (modifier, doc, userId) ->
smite doc, 'modModifier.feed doc', eval s
unless doc.feed instanceof Array
unless modifier.feed instanceof Array
smite modifier, doc, 'modifier, doc', eval s
# "s" {"feed":"nothing"} {"_id":"wiber","sending":[{"from":"picture5","to":"wiber5"},{"from":"picture5","to":"wiber5"}]} "modifier, userId" "server.coffee:83:59)
modifier.feed = []

afterModifier = {}
# feed balancing etc happens after the original update hits the db to let the db work
#TODO remove test feed function
@feedMe = (userId) ->
@feedMe = (docId) ->
fed = []
for i in 'abcdefghiklmo'
fed.push(generateRecommend i)
one = WI.update
_id: docId
,
'$pushAll':
'feed': fed
smite one, 'oneoneone done', eval s

return fed
modModifier.feed = (modifier, userId, doc) ->
unless modifier.feed instanceof Array
smite modifier, doc, 'modifier, userId', eval s
# "s" {"feed":"nothing"} {"_id":"wiber","sending":[{"from":"picture5","to":"wiber5"},{"from":"picture5","to":"wiber5"}]} "modifier, userId" "server.coffee:83:59)
modifier.feed = []
afterModifier = {}
# feed balancing etc happens after the original update hits the db to let the db work
afterModifier.feed = (modifier, doc, userId) ->
smite doc, 'doc afterModifier', eval s
docId = arguments[1]._id
smite arguments, docId, doc.feed.length, 'doc afterModifier', eval s
if !stackSize
stackSize = 10
userObject = WI.find
_id: doc._id
unless userObject.feed.length >= stackSize
query = feedMe userId
userObject.update
'$push':
feed: query
doc.journey.push
'feed': new Date().getTime()
smite query, stackSize, userObject, 'feed afterModifier', eval s
stackSize = 5

unless doc.feed.length >= stackSize
### WI.find({_id:'wiber'}).fetch()[0].feed # works
unless afterModifier[docId]
afterModifier[docId] = _.throttle feedMe(docId), 250
setTimeout (->
delete afterModifier[docId]
), 300
###
userObject = WI.findOne
_id: docId
smite userObject, userObject.feed.length, 'almost userObject', eval s
unless userObject.feed.length >= stackSize
smite feedMe(docId), 'feedMe(docId)', eval s

# continue with the feed update call to db and go call the method async while waiting
#Meteor.call 'stackBalance', userId, doc, (res, err) ->
smite modifier, userId, res, err, 'userId returned from stackBalance', eval s
# {"feed":"nothing"} null "modifier, userId" "server.coffee:68:52)
# {"feed":"nothing"} null "modifier, userId" "server.coffee:68:52)

WI.before.update (userId, doc, fieldNames, modifier, options) ->

for fieldName in fieldNames
# do we have a function for this fieldname?
if _.has(modModifier, fieldName)
smite fieldName, 'spinning modModifier', eval s
smite fieldName, doc, 'spinning modModifier', eval s
# modify the modifier so the update is redirected before hitting db
modifier = modModifier[fieldName] modifier, doc, userId
for i in arguments
smite i,'arguments', eval s

#smite modifier, doc, fieldNames, Meteor.default_server.method_handlers,'fieldname calling method', eval s
smite modifier = modModifier[fieldName] modifier, doc, userId

#smite eval(s), doc, doc.outbox, modifier, 'got before updated WI! on server! is last arg correctly modifier?'

#smite modifier, doc, fieldNames, Meteor.default_server.method_handlers,'fieldname calling method', eval s
#smite eval(s), doc, doc.outbox, modifier, 'got before updated WI! on server! is last arg correctly modifier?'


WIAfterUpdate = WI.after.update (userId, doc, fieldNames, modifier, options) ->
if !doc.journey
doc.journey = []

doc.journey.push
'serverOutbox': new Date().getTime()
for fieldName in fieldNames
# do we have a function for this fieldname?

if _.has(afterModifier, fieldName)
smite fieldName, doc, 'spinning afterModifier', eval s

smite fieldName, 'spinning afterModifier', eval s
# modify the modifier so the update is redirected before hitting db
modifier = afterModifier[fieldName] modifier, doc, userId
for i in arguments
smite arguments, 'after update arguments', eval s




Expand Down
166 changes: 166 additions & 0 deletions server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 07adfd3

Please sign in to comment.