Skip to content
This repository was archived by the owner on Aug 15, 2022. It is now read-only.

Commit c0a552e

Browse files
committed
activity cache WIP
1 parent 5167224 commit c0a552e

File tree

13 files changed

+169
-760
lines changed

13 files changed

+169
-760
lines changed

Cakefile.orig

Lines changed: 0 additions & 591 deletions
This file was deleted.

client/Framework/core/KD.coffee

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ String.prototype.capitalize = ()-> this.charAt(0).toUpperCase() + this.slice(1
2323
String.prototype.decapitalize = ()-> this.charAt(0).toLowerCase() + this.slice(1)
2424
String.prototype.trim = ()-> this.replace(/^\s+|\s+$/g,"")
2525

26-
# unless Array.prototype.last
27-
# Array.prototype.__defineGetter__ "last", -> this[this.length-1]
26+
unless Array.prototype.last
27+
Object.defineProperty Array.prototype, "last", get : -> this[this.length-1]
28+
29+
unless Array.prototype.first
30+
Object.defineProperty Array.prototype, "first", get : -> this[0]
2831

2932
# KD Global
3033
KD = @KD or {}

client/app/Applications/Activity.kdapplication/AppController.coffee

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,38 @@ class ActivityAppController extends AppController
7070

7171
@populateActivity()
7272

73+
7374
populateActivity:(options = {})->
7475

7576
@listController.showLazyLoader()
76-
@fetchCachedActivity options, (err, activities, overview)=>
77+
78+
@fetchCachedActivity options, (err, cache)=>
7779
if err then warn err
7880
else
79-
@listController.listActivities activities, overview
80-
@listController.hideLazyLoader()
81+
@sanitizeCache cache, (err, cache)=>
82+
83+
@listController.listActivities cache
84+
@listController.hideLazyLoader()
85+
isLoading = no
86+
87+
88+
sanitizeCache:(cache, callback)->
89+
90+
activities = []
91+
for activityId, activity of cache.activities
92+
activity.snapshot = activity.snapshot?.replace /"/g, '"'
93+
activities.push activity
94+
95+
96+
KD.remote.reviveFromSnapshots activities, (err, instances)->
97+
98+
for activity,i in activities
99+
cache.activities[activity._id].teaser = instances[i]
100+
101+
callback null, cache
102+
103+
104+
81105

82106
fetchCachedActivity:(options = {}, callback)->
83107

@@ -91,18 +115,13 @@ class ActivityAppController extends AppController
91115
error : (err)-> callback? err
92116
success : (cache)=>
93117
@listController.hideLazyLoader()
94-
if cache.length is 0
118+
if cache?.length is 0
95119
@listController.noActivityItem.show()
96-
callback? null, []
97120
return
98121

99-
cache.activities.map (a)-> a.snapshot = a.snapshot?.replace /"/g, '"'
122+
cache.overview.reverse()
100123

101-
KD.remote.reviveFromSnapshots cache.activities, (err, instances)=>
102-
# instanceMap = {}
103-
# instanceMap[instance._id] = instance for instance in instances
104-
callback? null, instances
105-
isLoading = no
124+
callback null, cache
106125

107126
# delete
108127
fetchActivityOverview:(callback)->

client/app/Applications/Activity.kdapplication/activitylistcontroller.coffee

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,19 @@ class ActivityListController extends KDListViewController
5454
id = KD.whoami().getId()
5555
id? and id in [activity.originId, activity.anchor?.id]
5656

57-
listActivities:(activities)->
58-
59-
# for item in overview
60-
# log item
61-
# unless /^CNewMemberBucket/.test item.type
62-
# @addItem activities[item.ids[0]]
63-
64-
# log activities
65-
# log overview
57+
listActivities:(cache)->
58+
59+
for item in cache.overview
60+
if item.ids.length > 1
61+
@addItem new NewMemberBucketData
62+
type : "CNewMemberBucketActivity"
63+
teasers : (cache.activities[id] for id in item.ids)
64+
count : item.count
65+
createdAt : item.createdAt
66+
else
67+
@addItem cache.activities[item.ids.first].teaser
6668

67-
@addItem activity for activity in activities when activity
6869
@teasersLoaded()
69-
# if group.type is "CNewMemberBucket"
70-
# @addItem new NewMemberBucketData
71-
# type : group.type
72-
# ids : group.ids
73-
# count : group.count
74-
# else
75-
# for id in group.ids
76-
# @addItem type : group.type, ids : [id]
7770

7871
teasersLoaded:->
7972
@emit "teasersLoaded"

client/app/Applications/Activity.kdapplication/views/newmemberbucket.coffee

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,7 @@ class NewMemberBucketView extends JView
1717

1818
super
1919

20-
@anchors = []
21-
22-
viewAppendedHelper:->
23-
24-
@group = new LinkGroup totalCount : @getData().count, @anchors
25-
26-
JView::viewAppended.call @
27-
28-
viewAppended:->
29-
30-
{length} = @getData().ids
31-
appManager.tell "Activity", "streamByIds", @getData().ids, (err, model)=>
32-
unless err
33-
if model
34-
snapshot = JSON.parse model.snapshot.replace /"/g, '"'
35-
@anchors.push snapshot.anchor
36-
37-
if length-- is 0
38-
@viewAppendedHelper()
39-
40-
41-
# @timer = @utils.wait 800, =>
42-
# @$('.fx').removeClass "out hidden"
43-
# @timer = @utils.wait 400, =>
44-
# @$('.fx').addClass "hidden"
20+
@group = new LinkGroup totalCount : @getData().count, @getData().teasers
4521

4622
click:->
4723

client/stylus/app.styl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ body
5252
input,textarea,button,select,option
5353
font-weight 400
5454

55+
#zikkim
56+
vendor transition, bottom .2s ease-in .2s
57+
5558
@keyframes pulse
5659
0%
5760
opacity .5

node_modules_koding/bongo-client/src/bongo.coffee

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Bongo extends EventEmitter
5252
{slice} = []
5353

5454
{extend} = require './src/util'
55-
55+
5656
{race, sequence, dash} = require 'sinkrow'
5757
{@daisy, @dash, @sequence, @race, @future} = require 'sinkrow'
5858

@@ -239,11 +239,11 @@ class Bongo extends EventEmitter
239239
else unless isNaN +method
240240
callback = @localStore.get(method)
241241
callback?.apply null, revived
242-
else
243-
console.warn 'Unhandleable message; dropping it on the floor.'
244-
console.trace()
245-
console.log message
246-
console.log method
242+
# else
243+
# console.warn 'Unhandleable message; dropping it on the floor.'
244+
# console.trace()
245+
# console.log message
246+
# console.log method
247247

248248
connect:(callback)->
249249
@channel = @mq.subscribe @channelName
@@ -295,7 +295,7 @@ class Bongo extends EventEmitter
295295
@authenticateUser()
296296
@emit 'ready'
297297

298-
changeLoggedInState:(state)->
298+
changeLoggedInState:(state)->
299299
@emit 'loggedInStateChanged', state
300300

301301
updateSessionToken:(token)->
@@ -307,7 +307,7 @@ class Bongo extends EventEmitter
307307

308308
use:(fn)->
309309
@stack.push fn
310-
310+
311311
if not isBrowser and module
312312
module.exports = Bongo
313313
else if window?

node_modules_koding/mongoop/index.js

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules_koding/mongoop/src/mongop.coffee

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
class MongoOp
2-
2+
33
if require? and module?
44
JsPath = require 'jspath' unless JsPath?
55
_ = require 'underscore' unless _?
66
else
77
{_, JsPath} = window
8-
8+
99
{isEqual} = _
1010
{setAt, getAt, deleteAt, pushAt, popAt} = JsPath
1111
{keys} = Object
12-
12+
1313
constructor:(operation)->
1414
return new MongoOp operation unless @ instanceof MongoOp
1515
@operation = operation
@@ -22,7 +22,7 @@ class MongoOp
2222
else
2323
@[operator] target, @operation[operator]
2424
return this
25-
25+
2626
forEachField:(fields, fn)->
2727
keys(fields).map (path)=>
2828
val = fields[path]
@@ -45,20 +45,20 @@ class MongoOp
4545
$addToSet collection, child for child in val.$each
4646
else
4747
$addToSet collection, val
48-
48+
4949
$push:(target, fields)->
5050
@forEachField fields, (path, val)-> pushAt target, path, val
51-
51+
5252
$pushAll:(target, fields)->
53-
@forEachField fields, (path, vals...)-> pushAt target, path, vals...
54-
53+
@forEachField fields, (path, vals)-> pushAt target, path, vals...
54+
5555
$pull:->
5656
throw new Error \
5757
"""
5858
This version of MongoOp does not implement $pull...
5959
Look for that in a future version. You can use $pullAll instead.
6060
"""
61-
61+
6262
$pullAll:(target, fields)->
6363
@forEachField fields, (path, val)->
6464
collection = getAt target, path
@@ -70,21 +70,21 @@ class MongoOp
7070

7171
$pop:(target, fields)->
7272
@forEachField fields, (path)-> popAt target, path
73-
73+
7474
$set:(target, fields)->
75-
@forEachField fields, (path, val)->
75+
@forEachField fields, (path, val)->
7676
setAt target, path, val
7777
val
78-
78+
7979
$unset:(target, fields)->
8080
@forEachField fields, (path)-> deleteAt target, path
81-
81+
8282
$rename:(target, fields)->
8383
@forEachField fields, (oldPath, newPath)->
8484
val = getAt target, oldPath
8585
deleteAt target, oldPath
8686
setAt target, newPath, val
87-
87+
8888
$inc:do->
8989
$inc = (val, amt)-> val += amt
9090
(target, fields)->

server/lib/server/bongo.coffee

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ modelsDir = 'workers/social/lib/social/models/'
1414
module.exports = new Bongo {
1515
mongo
1616
models: [
17-
"#{modelsDir}session.coffee"
18-
"#{modelsDir}account.coffee"
19-
"#{modelsDir}guest.coffee"
17+
"#{modelsDir}activity/cache.coffee"
2018
].map (path)-> nodePath.join projectRoot, path
2119
mq: new Broker mqOptions
2220
resourceName: webserver.queueName

0 commit comments

Comments
 (0)