Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #4127 from withspectrum/2.4.51
Browse files Browse the repository at this point in the history
2.4.51
  • Loading branch information
brianlovin authored Oct 25, 2018
2 parents f792221 + 40c0b88 commit 67f0212
Show file tree
Hide file tree
Showing 34 changed files with 150 additions and 891 deletions.
31 changes: 31 additions & 0 deletions api/migrations/20181024173616-indexes-for-digests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
exports.up = function(r, conn) {
return Promise.all([
r
.table('usersSettings')
.indexCreate(
'weeklyDigestEmail',
r.row('notifications')('types')('weeklyDigest')('email')
)
.run(conn),
r
.table('usersSettings')
.indexCreate(
'dailyDigestEmail',
r.row('notifications')('types')('dailyDigest')('email')
)
.run(conn),
]);
};

exports.down = function(r, conn) {
return Promise.all([
r
.table('usersSettings')
.indexDrop('weeklyDigestEmail')
.run(conn),
r
.table('usersSettings')
.indexDrop('dailyDigestEmail')
.run(conn),
]);
};
52 changes: 8 additions & 44 deletions chronos/models/community.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,56 +21,20 @@ export const getCommunities = (
export const getTopCommunities = (amount: number): Array<Object> => {
return db
.table('communities')
.pluck('id')
.run()
.then(communities => communities.map(community => community.id))
.then(communityIds => {
return Promise.all(
communityIds.map(community => {
return db
.table('usersCommunities')
.getAll([community, true], { index: 'communityIdAndIsMember' })
.count()
.run()
.then(count => {
return {
id: community,
count,
};
});
})
);
})
.then(data => {
let sortedCommunities = data
.sort((x, y) => {
return y.count - x.count;
})
.map(community => community.id)
.slice(0, amount);

return db
.table('communities')
.getAll(...sortedCommunities)
.filter(community => db.not(community.hasFields('deletedAt')))
.run();
});
.orderBy('memberCount')
.filter(community => community.hasFields('deletedAt').not())
.limit(amount)
.run();
};

export const getCommunitiesWithMinimumMembers = (
min: number = 2,
communityIds: Array<string>
) => {
return db
.table('usersCommunities')
.getAll(...communityIds, { index: 'communityId' })
.group('communityId')
.ungroup()
.filter(row =>
row('reduction')
.count()
.gt(min)
)
.map(row => row('group'))
.table('communities')
.filter(row => row('memberCount').ge(min))
.filter(community => community.hasFields('deletedAt').not())
.map(row => row('id'))
.run();
};
1 change: 0 additions & 1 deletion chronos/models/coreMetrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ export const getCount = (table: string, filter: mixed) => {
if (filter) {
return db
.table(table)
.filter(filter)
.filter(row => db.not(row.hasFields('deletedAt')))
.count()
.run();
Expand Down
48 changes: 10 additions & 38 deletions chronos/models/usersSettings.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,14 @@
// @flow
const { db } = require('./db');

export const getUsersForDigest = (
timeframe: string
): Promise<Array<Object>> => {
let range;
switch (timeframe) {
case 'daily': {
range = 'dailyDigest';
break;
}
case 'weekly': {
range = 'weeklyDigest';
break;
}
}

return (
db
.table('usersSettings')
.filter(row => row('notifications')('types')(range)('email').eq(true))
.eqJoin('userId', db.table('users'))
.zip()
.pluck(['userId', 'email', 'firstName', 'name', 'username', 'lastSeen'])
// save some processing time by making sure the user has an email address
.filter(row => row('email').ne(null))
// save some processing time by making sure the user has a username
.filter(row => row.hasFields('username').and(row('username').ne(null)))
// save some processing time by making sure the user was active in the last month
.filter(row =>
row
.hasFields('lastSeen')
.and(
row('lastSeen').during(db.now().sub(60 * 60 * 24 * 30), db.now())
)
)
.pluck(['userId', 'email', 'firstName', 'name', 'username'])
.distinct()
.run()
);
// prettier-ignore
export const getUsersForDigest = (timeframe: string): Promise<Array<Object>> => {
let range = timeframe === 'daily' ? 'dailyDigest' : 'weeklyDigest';
return db
.table('usersSettings')
.getAll(true, { index: `${range}Email` })
.eqJoin('userId', db.table('users'))
.zip()
.pluck(['userId', 'email', 'firstName', 'name', 'username'])
.run()
};
10 changes: 0 additions & 10 deletions chronos/queues/coreMetrics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ export default async () => {
// 13
const dmThreads = await getCount('directMessageThreads');

// 14
const threadMessages = await getCount('messages', { threadType: 'story' });

// 15
const dmMessages = await getCount('messages', {
threadType: 'directMessageThread',
});

const coreMetrics = {
dau,
wau,
Expand All @@ -97,8 +89,6 @@ export default async () => {
communities,
threads,
dmThreads,
threadMessages,
dmMessages,
};

try {
Expand Down
7 changes: 6 additions & 1 deletion chronos/queues/digests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ export default async (job: DigestJob) => {
debug('\n ❌ No threads found for this digest');
return;
}

debug('\n ⚙️ Fetched threads for digest');

const threadsWithData = await attachDataToThreads(threads);
if (!threadsWithData || threadsWithData.length === 0) {
debug('\n ❌ No threads with data eligible for this digest');
return;
}

debug('\n ⚙️ Processed threads with data');

// 2
Expand All @@ -60,6 +62,8 @@ export default async (job: DigestJob) => {

// 4
const usersPromises = users.map(user => {
if (!user.email || !user.username) return null;

try {
return addQueue(
PROCESS_INDIVIDUAL_DIGEST,
Expand All @@ -72,12 +76,13 @@ export default async (job: DigestJob) => {
} catch (err) {
debug(err);
Raven.captureException(err);
return null;
}
});

debug('\n ⚙️ Created individual jobs for each users digest');
try {
return Promise.all(usersPromises);
return Promise.all(usersPromises.filter(Boolean));
} catch (err) {
debug('❌ Error in job:\n');
debug(err);
Expand Down
42 changes: 17 additions & 25 deletions cypress/integration/thread/action_bar_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,21 @@ const pinThread = () => {
const triggerThreadDelete = () => {
cy.get('[data-cy="thread-dropdown-delete"]').click();
cy.get('[data-cy="delete-button"]').should('be.visible');
cy
.get('div.ReactModal__Overlay')
cy.get('div.ReactModal__Overlay')
.should('be.visible')
.click('topLeft');
};

const triggerMovingThread = () => {
cy.get('[data-cy="thread-dropdown-move"]').click();
cy.get('[data-cy="move-thread-modal"]').should('be.visible');
cy
.get('div.ReactModal__Overlay')
cy.get('div.ReactModal__Overlay')
.should('be.visible')
.click('topLeft');
};

const openSettingsDropdown = () => {
cy
.get('[data-cy="thread-actions-dropdown-trigger"]')
cy.get('[data-cy="thread-actions-dropdown-trigger"]')
.should('be.visible')
.click();
};
Expand All @@ -80,15 +77,12 @@ describe('action bar renders', () => {

it('should render', () => {
cy.get('[data-cy="thread-view"]').should('be.visible');
cy
.get('[data-cy="thread-notifications-login-capture"]')
.should('be.visible');
cy.get('[data-cy="thread-facebook-button"]').should('be.visible');
cy.get('[data-cy="thread-tweet-button"]').should('be.visible');
cy.get('[data-cy="thread-copy-link-button"]').should('be.visible');
cy
.get('[data-cy="thread-actions-dropdown-trigger"]')
.should('not.be.visible');
cy.get('[data-cy="thread-actions-dropdown-trigger"]').should(
'not.be.visible'
);
});
});

Expand All @@ -104,9 +98,9 @@ describe('action bar renders', () => {
cy.get('[data-cy="thread-facebook-button"]').should('be.visible');
cy.get('[data-cy="thread-tweet-button"]').should('be.visible');
cy.get('[data-cy="thread-copy-link-button"]').should('be.visible');
cy
.get('[data-cy="thread-actions-dropdown-trigger"]')
.should('not.be.visible');
cy.get('[data-cy="thread-actions-dropdown-trigger"]').should(
'not.be.visible'
);
});
});

Expand All @@ -122,9 +116,9 @@ describe('action bar renders', () => {
cy.get('[data-cy="thread-facebook-button"]').should('be.visible');
cy.get('[data-cy="thread-tweet-button"]').should('be.visible');
cy.get('[data-cy="thread-copy-link-button"]').should('be.visible');
cy
.get('[data-cy="thread-actions-dropdown-trigger"]')
.should('not.be.visible');
cy.get('[data-cy="thread-actions-dropdown-trigger"]').should(
'not.be.visible'
);
});
});

Expand All @@ -140,9 +134,9 @@ describe('action bar renders', () => {
cy.get('[data-cy="thread-facebook-button"]').should('not.be.visible');
cy.get('[data-cy="thread-tweet-button"]').should('not.be.visible');
cy.get('[data-cy="thread-copy-link-button"]').should('be.visible');
cy
.get('[data-cy="thread-actions-dropdown-trigger"]')
.should('not.be.visible');
cy.get('[data-cy="thread-actions-dropdown-trigger"]').should(
'not.be.visible'
);
});
});

Expand Down Expand Up @@ -192,8 +186,7 @@ describe('action bar renders', () => {
cy.get('[data-cy="save-thread-edit-button"]').should('be.visible');
const title = 'Some new thread';
cy.get('[data-cy="rich-text-editor"]').should('be.visible');
cy
.get('[data-cy="thread-editor-title-input"]')
cy.get('[data-cy="thread-editor-title-input"]')
.clear()
.type(title);
cy.get('[data-cy="save-thread-edit-button"]').click();
Expand All @@ -205,8 +198,7 @@ describe('action bar renders', () => {
cy.get('[data-cy="save-thread-edit-button"]').should('be.visible');
const originalTitle = 'The first thread! 🎉';
cy.get('[data-cy="rich-text-editor"]').should('be.visible');
cy
.get('[data-cy="thread-editor-title-input"]')
cy.get('[data-cy="thread-editor-title-input"]')
.clear()
.type(originalTitle);
cy.get('[data-cy="save-thread-edit-button"]').click();
Expand Down
4 changes: 2 additions & 2 deletions mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"react-native-picker-select": "^3.1.3",
"react-native-tab-view": "^0.0.78",
"react-native-typography": "^1.4.0",
"react-navigation": "^2.18.0",
"react-navigation": "^2.18.1",
"react-navigation-props-mapper": "^0.1.3",
"recompose": "^0.26.0",
"redraft": "^0.10.2",
Expand All @@ -40,7 +40,7 @@
"exp": "^52.0.0",
"jest": "^22.4.4",
"jest-expo": "^28.0.0",
"react-test-renderer": "^16.5.2"
"react-test-renderer": "^16.6.0"
},
"scripts": {
"dev": "exp start .",
Expand Down
Loading

0 comments on commit 67f0212

Please sign in to comment.