-
Notifications
You must be signed in to change notification settings - Fork 314
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(uaa-logging): Log UAA Parity data #3629
Changes from all commits
366e5c5
570d14b
93190bc
47eec0d
76da7a5
7edce88
b2a4b9a
4add4dd
bf4d39b
9636014
f256865
1a5b322
ff88b8e
6ee0690
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,6 +89,7 @@ import type { | |
Tasks, | ||
ThreadedComments as ThreadedCommentsType, | ||
} from '../common/types/feed'; | ||
import { collapseFeedState } from '../elements/content-sidebar/activity-feed/activity-feed/activityFeedUtils'; | ||
|
||
const TASK_NEW_INITIAL_STATUS = TASK_NEW_NOT_STARTED; | ||
|
||
|
@@ -550,6 +551,7 @@ class Feed extends Base { | |
shouldShowVersions?: boolean, | ||
shouldUseUAA?: boolean, | ||
} = {}, | ||
logAPIParity?: Function, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: function header definition |
||
): void { | ||
const { id, permissions = {} } = file; | ||
const cachedItems = this.getCachedItems(id); | ||
|
@@ -571,23 +573,16 @@ class Feed extends Base { | |
this.errorCallback = onError; | ||
|
||
// Using the UAA File Activities endpoint replaces the need for these calls | ||
const annotationsPromise = | ||
!shouldUseUAA && shouldShowAnnotations | ||
? this.fetchAnnotations(permissions, shouldShowReplies) | ||
: Promise.resolve(); | ||
const annotationsPromise = shouldShowAnnotations | ||
? this.fetchAnnotations(permissions, shouldShowReplies) | ||
: Promise.resolve(); | ||
const commentsPromise = () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: commentsPromise could be updated to match the ternary pattern of the others? |
||
if (shouldUseUAA) { | ||
return Promise.resolve(); | ||
} | ||
|
||
return shouldShowReplies ? this.fetchThreadedComments(permissions) : this.fetchComments(permissions); | ||
}; | ||
const tasksPromise = !shouldUseUAA && shouldShowTasks ? this.fetchTasksNew() : Promise.resolve(); | ||
const appActivityPromise = | ||
!shouldUseUAA && shouldShowAppActivity ? this.fetchAppActivity(permissions) : Promise.resolve(); | ||
const versionsPromise = !shouldUseUAA && shouldShowVersions ? this.fetchVersions() : Promise.resolve(); | ||
const currentVersionPromise = | ||
!shouldUseUAA && shouldShowVersions ? this.fetchCurrentVersion() : Promise.resolve(); | ||
const tasksPromise = shouldShowTasks ? this.fetchTasksNew() : Promise.resolve(); | ||
const appActivityPromise = shouldShowAppActivity ? this.fetchAppActivity(permissions) : Promise.resolve(); | ||
const versionsPromise = shouldShowVersions ? this.fetchVersions() : Promise.resolve(); | ||
const currentVersionPromise = shouldShowVersions ? this.fetchCurrentVersion() : Promise.resolve(); | ||
|
||
const annotationActivityType = | ||
shouldShowAnnotations && permissions[PERMISSION_CAN_VIEW_ANNOTATIONS] | ||
|
@@ -622,29 +617,54 @@ class Feed extends Base { | |
} | ||
}; | ||
|
||
const v2Promises = [ | ||
versionsPromise, | ||
currentVersionPromise, | ||
commentsPromise(), | ||
tasksPromise, | ||
appActivityPromise, | ||
annotationsPromise, | ||
]; | ||
|
||
const fetchV2FeedItems = async promises => { | ||
return Promise.all(promises).then( | ||
([versions: ?FileVersions, currentVersion: ?BoxItemVersion, ...feedItems]) => { | ||
const versionsWithCurrent = currentVersion | ||
? this.versionsAPI.addCurrentVersion(currentVersion, versions, this.file) | ||
: undefined; | ||
return sortFeedItems(versionsWithCurrent, ...feedItems); | ||
}, | ||
); | ||
}; | ||
|
||
const compareV2AndUaaFeedItems = async (uaaFeedItems, uaaResponse) => { | ||
Comment on lines
+629
to
+640
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i don't think you need |
||
fetchV2FeedItems(v2Promises).then(v2FeedItems => { | ||
const transformedV2FeedItems = collapseFeedState(v2FeedItems); | ||
const transformedUAAFeedItems = collapseFeedState(uaaFeedItems); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: inconsistency of |
||
|
||
if (logAPIParity) { | ||
logAPIParity({ | ||
uaaResponse, | ||
uaaFeedItems: transformedUAAFeedItems, | ||
v2FeedItems: transformedV2FeedItems, | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
if (shouldUseUAA) { | ||
fileActivitiesPromise.then(response => { | ||
if (!response) { | ||
return; | ||
} | ||
|
||
const parsedFeedItems = getParsedFileActivitiesResponse(response); | ||
handleFeedItems(parsedFeedItems); | ||
const uaaFeedItems = getParsedFileActivitiesResponse(response); | ||
compareV2AndUaaFeedItems(uaaFeedItems, response); | ||
handleFeedItems(uaaFeedItems); | ||
}); | ||
} else { | ||
Promise.all([ | ||
versionsPromise, | ||
currentVersionPromise, | ||
commentsPromise(), | ||
tasksPromise, | ||
appActivityPromise, | ||
annotationsPromise, | ||
]).then(([versions: ?FileVersions, currentVersion: ?BoxItemVersion, ...feedItems]) => { | ||
const versionsWithCurrent = currentVersion | ||
? this.versionsAPI.addCurrentVersion(currentVersion, versions, this.file) | ||
: undefined; | ||
const sortedFeedItems = sortFeedItems(versionsWithCurrent, ...feedItems); | ||
handleFeedItems(sortedFeedItems); | ||
fetchV2FeedItems(v2Promises).then(v2FeedItems => { | ||
handleFeedItems(v2FeedItems); | ||
}); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ import { | |
ORIGIN_ACTIVITY_SIDEBAR, | ||
SIDEBAR_VIEW_ACTIVITY, | ||
TASK_COMPLETION_RULE_ALL, | ||
METRIC_TYPE_UAA_PARITY_METRIC, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: this list is alphasorted |
||
} from '../../constants'; | ||
import type { | ||
TaskCompletionRule, | ||
|
@@ -736,6 +737,7 @@ class ActivitySidebar extends React.PureComponent<Props, State> { | |
shouldShowVersions, | ||
shouldUseUAA, | ||
}, | ||
shouldUseUAA ? this.logAPIParity : undefined, | ||
); | ||
} | ||
|
||
|
@@ -795,6 +797,22 @@ class ActivitySidebar extends React.PureComponent<Props, State> { | |
this.setState({ feedItems, activityFeedError: undefined }); | ||
}; | ||
|
||
/** | ||
* Logs diff between UAA and v2 API data | ||
* | ||
* @param {{}[]} responseParity array of aggragated responses from UAA and v2 | ||
* @param {{}} parsedDataParity parsed data from UAA and v2 | ||
* @return {void} | ||
*/ | ||
logAPIParity = (parityData: { uaaFeedItems: FeedItems, v2FeedItems: FeedItems }): void => { | ||
const { logger } = this.props; | ||
|
||
logger.onPreviewMetric({ | ||
parityData, | ||
type: METRIC_TYPE_UAA_PARITY_METRIC, | ||
}); | ||
}; | ||
|
||
/** | ||
* Handles a failed feed item fetch | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's odd for an api file to be importing from a component utility file