This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4127 from withspectrum/2.4.51
2.4.51
- Loading branch information
Showing
34 changed files
with
150 additions
and
891 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.