@@ -31,7 +31,7 @@ public Commons(
3131 final Vote likeType ) {
3232 this .node = node ;
3333 persistentCommonsMap =
34- new PersistentUidMap (node .getMuid () + "" + likeType );
34+ new PersistentUidMap (node .getUid () + "" + likeType );
3535 this .likeType = likeType ;
3636 }
3737
@@ -71,27 +71,35 @@ public long[] getCommonNodes(final long muid) {
7171 }
7272
7373 /**
74- * Updates the commons of node and writes the data to disk
74+ * Updates the commons of node and writes the data to disk if nod has a
75+ * large in degree
7576 */
76- public void update () {
77+ public void updateLargeNode () {
7778 final int now = (int ) (System .currentTimeMillis () / 1000l );
7879
7980 /*
80- * Update all outgoing nodes
81+ * Update all incoming nodes if this node is large.
8182 */
82- final long [] outNodes = node .getLikesOut (Vote .UP ).toArray ();
83- if (outNodes != null ) {
84- for (long friendUUID : outNodes ) {
85- if (friendUUID == 0 ) {
86- break ;
83+ final long [] inNodes = node .getLikesIn (Vote .UP ).toArray ();
84+ if (inNodes != null && inNodes .length >= Node .LARGE_NODE_DEGREE ) {
85+ if (inNodes != null ) {
86+ for (long friendUUID : inNodes ) {
87+ if (friendUUID == 0 ) {
88+ break ;
89+ }
90+ (NodeFactory .getNode (friendUUID )).updateCommons (node
91+ .getUid ());
8792 }
88- updateFriend (NodeFactory .getNode (friendUUID ), false );
8993 }
9094 }
9195
9296 persistentCommonsMap .setUpdateTimeStamp (now );
9397 }
9498
99+ public void updateNode (final long likedNode ) {
100+ updateFriend (NodeFactory .getNode (likedNode ), false );
101+ }
102+
95103 /**
96104 * Adds the friend to all entities in the commonsMap liked by the friend
97105 * node.
@@ -100,22 +108,26 @@ public void update() {
100108 * The friend to be added to the commonsMap
101109 */
102110 public void friendAdded (final Node friend ) {
111+ /*
112+ * Update the commons with friend
113+ */
103114 updateFriend (friend , true );
104115
105116 /*
106- * Instead of frequently running LikeService.updateAllNodes() we could
107- * run following code. The problem here is that big nodes would trigger
108- * these expensive calls much too often.
117+ * Update all incoming nodes if this node is not too large.
109118 */
110- // final long[] inNodes = node.getLikesIn(Vote.UP).toArray();
111- // if (inNodes != null) {
112- // for (long friendUUID : inNodes) {
113- // if (friendUUID == 0) {
114- // break;
115- // }
116- // (NodeFactory.getNode(friendUUID)).updateCommons();
117- // }
118- // }
119+ final long [] inNodes = node .getLikesIn (Vote .UP ).toArray ();
120+ if (inNodes == null || inNodes .length < Node .LARGE_NODE_DEGREE ) {
121+ if (inNodes != null ) {
122+ for (long friendUUID : inNodes ) {
123+ if (friendUUID == 0 ) {
124+ break ;
125+ }
126+ (NodeFactory .getNode (friendUUID )).updateCommons (node
127+ .getUid ());
128+ }
129+ }
130+ }
119131 }
120132
121133 /**
@@ -130,14 +142,14 @@ public void friendRemoved(final Node friend) {
130142 /*
131143 * Remove the friend from the commons list of the liked entity
132144 */
133- persistentCommonsMap .remove (outID , friend .getMuid ());
145+ persistentCommonsMap .remove (outID , friend .getUid ());
134146 }
135147
136148 for (long outID : friend .getLikesOut (Vote .DOWN )) {
137149 /*
138150 * Remove the friend from the commons list of the liked entity
139151 */
140- persistentCommonsMap .remove (outID , friend .getMuid ());
152+ persistentCommonsMap .remove (outID , friend .getUid ());
141153 }
142154 }
143155
@@ -160,15 +172,15 @@ public void updateFriend(final Node friend, final boolean ignoreTimestamp) {
160172 int searchTS =
161173 ignoreTimestamp ? 0 : persistentCommonsMap
162174 .getLastUpdateTimeStamp ();
163- for (Like like : friend .getLikesFromTimeOn (searchTS )) {
164- if (like .getMUID () == node .getMuid ()) {
175+ for (Like like : friend .getLikeHistoryFromTimeOn (searchTS )) {
176+ if (like .getMUID () == node .getUid ()) {
165177 continue ;
166178 }
167179 if (like .getVote () == likeType ) {
168180 /*
169181 * Q1 node -> friend -> likedNode
170182 */
171- persistentCommonsMap .append (like .getMUID (), friend .getMuid ());
183+ persistentCommonsMap .append (like .getMUID (), friend .getUid ());
172184
173185 /*
174186 * Q2 node -> likedNode && node -> friend -> likedNode FIXME:
@@ -178,19 +190,19 @@ public void updateFriend(final Node friend, final boolean ignoreTimestamp) {
178190 * friend.getLikedNodes()
179191 */
180192 if (node .getLikesOut (likeType ).contains (like .getMUID ())) {
181- persistentCommonsMap . append ( friend . getMuid (),
182- like .getMUID ());
193+ persistentCommonsMap
194+ . append ( friend . getUid (), like .getMUID ());
183195 }
184196 } else {
185- persistentCommonsMap .remove (like .getMUID (), friend .getMuid ());
186- persistentCommonsMap .remove (friend .getMuid (), like .getMUID ());
197+ persistentCommonsMap .remove (like .getMUID (), friend .getUid ());
198+ persistentCommonsMap .remove (friend .getUid (), like .getMUID ());
187199 }
188200 }
189201 }
190202
191203 @ Override
192204 public String toString () {
193- return node .getMuid () + "(" + likeType + "):\n "
205+ return node .getUid () + "(" + likeType + "):\n "
194206 + persistentCommonsMap .toString ();
195207 }
196208}
0 commit comments