fix query, add filter for deleted users, switch temporarily to u.creation_time
This commit is contained in:
@@ -246,16 +246,11 @@ func (c *EmailNotificationController) setStorageLimitExceededMailerJobStatus(isS
|
||||
|
||||
func (c *EmailNotificationController) SendFamilyNudgeEmail() error {
|
||||
thirtyDaysDuration := 30 * 24 * t.Hour
|
||||
thirtyDaysAgo := t.Now().Add(-thirtyDaysDuration)
|
||||
formattedTime := thirtyDaysAgo.Format("2006-01-02 15:04:05.999999")
|
||||
|
||||
subscribedUsers, subUsersErr := c.UserRepo.GetSubscribedUsersWithoutFamily(formattedTime)
|
||||
subscribedUsers, subUsersErr := c.UserRepo.GetSubscribedUsersWithoutFamily((30))
|
||||
if subUsersErr != nil {
|
||||
return stacktrace.Propagate(subUsersErr, "Failed to get subscribers")
|
||||
}
|
||||
|
||||
for _, user := range subscribedUsers {
|
||||
|
||||
creationTime := t.Unix(0, user.CreationTime)
|
||||
timeSinceCreation := t.Since(creationTime)
|
||||
if timeSinceCreation >= thirtyDaysDuration {
|
||||
|
||||
@@ -130,13 +130,13 @@ func (repo *UserRepository) GetAll(sinceTime int64, tillTime int64) ([]ente.User
|
||||
}
|
||||
|
||||
// GetSubscribedUsers will return the list of all subscribed.
|
||||
func (repo *UserRepository) GetSubscribedUsersWithoutFamily(duration string) ([]ente.User, error) {
|
||||
func (repo *UserRepository) GetSubscribedUsersWithoutFamily(accountAgeInDays int64) ([]ente.User, error) {
|
||||
rows, err := repo.DB.Query(`SELECT u.user_id, u.encrypted_email, u.email_decryption_nonce, u.email_hash, s.created_at
|
||||
FROM subscriptions s
|
||||
INNER JOIN users u ON s.user_id = u.user_id
|
||||
WHERE s.created_at >= $1
|
||||
AND u.family_admin_id IS NULL
|
||||
AND s.product_id != 'free'`, duration)
|
||||
FROM subscriptions s
|
||||
INNER JOIN users u ON s.user_id = u.user_id
|
||||
WHERE u.creation_time <= $1 AND u.family_admin_id IS NULL
|
||||
AND s.product_id != 'free'
|
||||
AND u.email_hash NOT LIKE 'deleted+'`, time.MicrosecondBeforeDays(int(accountAgeInDays)))
|
||||
if err != nil {
|
||||
return nil, stacktrace.Propagate(err, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user