r7168 - dumbhippo/trunk/server/src/com/dumbhippo/server/impl



Author: marinaz
Date: 2008-01-09 17:09:46 -0600 (Wed, 09 Jan 2008)
New Revision: 7168

Modified:
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
   dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java
Log:
Don't publish Facebook news feed updates about each comment or each played track. 
Allow for 6 hours to go by when no event of such type happens for a given block
and participant pair before publishing a new update. 

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2008-01-09 22:53:17 UTC (rev 7167)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/FacebookTrackerBean.java	2008-01-09 23:09:46 UTC (rev 7168)
@@ -8,7 +8,6 @@
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
-import java.util.Random;
 import java.util.Set;
 import java.util.concurrent.Callable;
 
@@ -307,10 +306,6 @@
 	@TransactionAttribute(TransactionAttributeType.NEVER)
 	public void publishUserAction(final Block block, final User user) {		
 		TxUtils.assertNoTransaction();
-		
-    	// let's publish Facebook news items about roughly one of 20 tracks the user plays
-    	if (block.getBlockType() == BlockType.MUSIC_PERSON && (new Random()).nextInt(20) != 19)
-    		return;
     	
 		try {
 			FacebookAccount facebookAccount = TxUtils.runInTransaction(new Callable<FacebookAccount>() {

Modified: dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java
===================================================================
--- dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java	2008-01-09 22:53:17 UTC (rev 7167)
+++ dumbhippo/trunk/server/src/com/dumbhippo/server/impl/StackerBean.java	2008-01-09 23:09:46 UTC (rev 7168)
@@ -390,13 +390,18 @@
 		}
 	}
 	
-	private void updateParticipantUserBlockData(final Block block, final Guid participantId, final StackReason reason) throws RetryException {
-		TxUtils.runNeedsRetry(new TxRunnable() {
-			public void run() {
+	private Pair<Long, StackReason> updateParticipantUserBlockData(final Block block, final Guid participantId, final StackReason reason) throws RetryException {
+		return TxUtils.runNeedsRetry(new TxCallable<Pair<Long, StackReason>>() {
+			public Pair<Long, StackReason> call() throws RetryException {
+				Pair<Long, StackReason> previousParticipation = new Pair<Long, StackReason>(Long.valueOf(-1), null);
 				User participant = em.find(User.class, participantId.toString());
 				UserBlockData userData = queryUserBlockData(block, participant);
 				if (userData != null) {
 					userData.setDeleted(false);
+					
+					if (userData.getParticipated())
+						previousParticipation = new Pair<Long, StackReason>(userData.getParticipatedTimestamp().getTime(), userData.getParticipatedReason());
+					
 					userData.setParticipatedTimestamp(block.getTimestamp());
 					userData.setParticipatedReason(reason);
 					if (!userData.isIgnored())
@@ -408,12 +413,15 @@
 				}
 				
 				DataService.currentSessionRW().feedChanged(UserDMO.class, participantId, "stack", block.getTimestampAsLong());
+				
+				return previousParticipation;
 			}
 		});
 	}
 	
 	// Don't call directly, RetryException is added in the wrapper for readability
-	private void updateUserBlockDatasInternal(Block block, Set<User> desiredUsers, Guid participantId, StackReason reason) {
+	// returns a pair with information about previous participation by the current participant
+	private Pair<Long, StackReason> updateUserBlockDatasInternal(Block block, Set<User> desiredUsers, Guid participantId, StackReason reason) {
 		ReadWriteSession session = DataService.getModel().currentSessionRW();
 
 		int addCount;
@@ -421,6 +429,8 @@
 		
 		Set<Guid> affectedGuids = new HashSet<Guid>();
 		
+		Pair<Long, StackReason> previousParticipation = new Pair<Long, StackReason>(Long.valueOf(-1), null);
+		
 		// be sure we have the right UserBlockData. This would be a lot saner to do
 		// at the point where it changes... e.g. when people add/remove friends, 
 		// or join/leave groups, instead of the expensive query and fixup here.
@@ -451,6 +461,10 @@
 					addCount += 1;
 				old.setDeleted(false);
 				if (u.getGuid().equals(participantId)) {
+					
+					if (old.getParticipated())
+						previousParticipation = new Pair<Long, StackReason>(old.getParticipatedTimestamp().getTime(), old.getParticipatedReason());
+
 					old.setParticipatedTimestamp(block.getTimestamp());
 					old.setParticipatedReason(reason);
 				}
@@ -482,14 +496,16 @@
 		
 		BlockEvent event = new BlockEvent(block.getGuid(), block.getTimestampAsLong(), affectedGuids);
 		LiveState.getInstance().queueUpdate(event);
+		
+		return previousParticipation;
 	}
 	
-	private void updateUserBlockDatas(final Block block, final Guid participantId, final StackReason reason) throws RetryException {
+	private Pair<Long, StackReason> updateUserBlockDatas(final Block block, final Guid participantId, final StackReason reason) throws RetryException {
 		final Set<User> desiredUsers = getHandler(block).getInterestedUsers(block);
 
-		TxUtils.runNeedsRetry(new TxRunnable() {
-			public void run() throws RetryException {
-				updateUserBlockDatasInternal(block, desiredUsers, participantId, reason);
+		return TxUtils.runNeedsRetry(new TxCallable<Pair<Long, StackReason>>() {
+			public Pair<Long, StackReason> call() throws RetryException {
+				return updateUserBlockDatasInternal(block, desiredUsers, participantId, reason);
 			}
 		});
 	}
@@ -717,14 +733,18 @@
 			public void run() throws RetryException {
 				DataService.getModel().initializeReadWriteSession(SystemViewpoint.getInstance());
 				
+				Pair<Long, StackReason> previousParticipation = new Pair<Long, StackReason>(Long.valueOf(-1), null);;
+				
 				Block attached = em.find(Block.class, block.getId());
 				if (updateAllUserBlockDatas) {
-				    updateUserBlockDatas(attached, (participant != null ? participant.getGuid() : null), reason);
+				    previousParticipation = updateUserBlockDatas(attached, (participant != null ? participant.getGuid() : null), reason);
 			    } else if (participant != null) {
-			        updateParticipantUserBlockData(attached, participant.getGuid(), reason);	
+			        previousParticipation = updateParticipantUserBlockData(attached, participant.getGuid(), reason);	
 			    }				
 				updateGroupBlockDatas(attached, isGroupParticipation, reason);
 
+				final Pair<Long, StackReason> previousParticipationFinal = previousParticipation;
+				
 				// FACEBOOK_EVENT blocks are never public, but we might as well check explicitly.
 				// We'll need to change this logic if we want to display some private blocks to
 				// a subset of person's friends who can also see those private blocks on Mugshot.
@@ -732,7 +752,27 @@
 				    TxUtils.runOnCommit(new Runnable() {
 					    public void run() {
 					    	facebookTracker.updateFbmlForUser(participant);
-					        facebookTracker.publishUserAction(block, participant);
+					    	
+					    	// We do not want to publish repeated user actions reflected by the same block, such as 
+					    	// chatting or playing music. 
+					    	// If we kept track of when we last published a story about the block, we would be able
+					    	// to publish a story about a similar activity after a certain amount of time from a previous
+					    	// story. However, we currently only keep track of when the user last participated in
+					    	// a certain activity, as a result this code will publish a new story only after a user
+					    	// did not participate in that activity for a certain amount of time. Such as, if the user
+					    	// did not play music for more than 6 hours, but then started playing it again, or if the user
+					    	// did not chat about something for 6 hours, but then had something new to say about it.
+					    	// This is fine because it allows us to create notifications when new events happen.
+					    	// The time interval can be different for different block types or stack reasons.
+					    	// The downside of this logic is that if someone plays music every 5 hours or comments on
+					    	// a block every 5 hours, we'll never create a new update about it after the first one.
+					    	if (previousParticipationFinal.getSecond() == null || 
+					            !previousParticipationFinal.getSecond().equals(reason) ||
+								previousParticipationFinal.getFirst() < (new Date().getTime()) - 6 * 60 * 60 * 1000) {
+					    		
+					    	    facebookTracker.publishUserAction(block, participant);	
+					    		 
+					    	}      
 					    }
 				    });
 				}	 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]