Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Q
question2answer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
outils
question2answer
Commits
306a9bec
Commit
306a9bec
authored
Aug 16, 2018
by
pupi1985
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Apply some early returns in function qa_mailing_perform_step()
parent
de02a7fc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
33 deletions
+38
-33
mailing.php
qa-include/app/mailing.php
+38
-33
No files found.
qa-include/app/mailing.php
View file @
306a9bec
...
...
@@ -63,51 +63,56 @@ function qa_mailing_perform_step()
$lastuserid
=
qa_opt
(
'mailing_last_userid'
);
if
(
strlen
(
$lastuserid
))
{
$thistime
=
time
();
$lasttime
=
qa_opt
(
'mailing_last_timestamp'
);
$perminute
=
qa_opt
(
'mailing_per_minute'
);
if
(
strlen
(
$lastuserid
)
==
0
)
{
return
;
}
if
((
$lasttime
-
$thistime
)
>
60
)
// if it's been a while, we assume there hasn't been continuous mailing...
$lasttime
=
$thistime
-
1
;
// ... so only do 1 second's worth
else
// otherwise...
$lasttime
=
max
(
$lasttime
,
$thistime
-
6
);
// ... don't do more than 6 seconds' worth
$thistime
=
time
();
$lasttime
=
qa_opt
(
'mailing_last_timestamp'
);
$perminute
=
qa_opt
(
'mailing_per_minute'
);
$count
=
min
(
floor
((
$thistime
-
$lasttime
)
*
$perminute
/
60
),
100
);
// don't do more than 100 messages at a time
if
((
$lasttime
-
$thistime
)
>
60
)
// if it's been a while, we assume there hasn't been continuous mailing...
$lasttime
=
$thistime
-
1
;
// ... so only do 1 second's worth
else
// otherwise...
$lasttime
=
max
(
$lasttime
,
$thistime
-
6
);
// ... don't do more than 6 seconds' worth
if
(
$count
>
0
)
{
qa_opt
(
'mailing_last_timestamp'
,
$thistime
+
30
);
// prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex)
$count
=
min
(
floor
((
$thistime
-
$lasttime
)
*
$perminute
/
60
),
100
);
// don't do more than 100 messages at a time
$sentusers
=
0
;
$users
=
qa_db_users_get_mailing_next
(
$lastuserid
,
$count
);
if
(
$count
==
0
)
{
return
;
}
if
(
count
(
$users
))
{
foreach
(
$users
as
$user
)
{
$lastuserid
=
max
(
$lastuserid
,
$user
[
'userid'
]);
}
qa_opt
(
'mailing_last_timestamp'
,
$thistime
+
30
);
// prevents a parallel call to qa_mailing_perform_step() from sending messages, unless we're very unlucky with timing (poor man's mutex)
qa_opt
(
'mailing_last_userid'
,
$lastuserid
)
;
qa_opt
(
'mailing_done_users'
,
qa_opt
(
'mailing_done_users'
)
+
count
(
$users
)
);
$sentusers
=
0
;
$users
=
qa_db_users_get_mailing_next
(
$lastuserid
,
$count
);
$isModeratingUsers
=
qa_opt
(
'moderate_users'
);
if
(
count
(
$users
))
{
foreach
(
$users
as
$user
)
{
$lastuserid
=
max
(
$lastuserid
,
$user
[
'userid'
]);
}
foreach
(
$users
as
$user
)
{
if
((
$user
[
'flags'
]
&
QA_USER_FLAGS_NO_MAILINGS
)
||
// exclude users who don't want to get the mailings
(
$user
[
'flags'
]
&
QA_USER_FLAGS_USER_BLOCKED
)
||
// exclude blocked users
(
$isModeratingUsers
&&
(
$user
[
'level'
]
<
QA_USER_LEVEL_APPROVED
)))
{
// if moderating users exclude unapproved users
continue
;
}
qa_opt
(
'mailing_last_userid'
,
$lastuserid
);
qa_opt
(
'mailing_done_users'
,
qa_opt
(
'mailing_done_users'
)
+
count
(
$users
));
qa_mailing_send_one
(
$user
[
'userid'
],
$user
[
'handle'
],
$user
[
'email'
],
$user
[
'emailcode'
]);
$sentusers
++
;
}
$isModeratingUsers
=
qa_opt
(
'moderate_users'
);
qa_opt
(
'mailing_last_timestamp'
,
$lasttime
+
$sentusers
*
60
/
$perminute
);
// can be floating point result, based on number of mails actually sent
foreach
(
$users
as
$user
)
{
if
((
$user
[
'flags'
]
&
QA_USER_FLAGS_NO_MAILINGS
)
||
// exclude users who don't want to get the mailings
(
$user
[
'flags'
]
&
QA_USER_FLAGS_USER_BLOCKED
)
||
// exclude blocked users
(
$isModeratingUsers
&&
(
$user
[
'level'
]
<
QA_USER_LEVEL_APPROVED
)))
{
// if moderating users exclude unapproved users
continue
;
}
}
else
qa_mailing_stop
()
;
qa_mailing_send_one
(
$user
[
'userid'
],
$user
[
'handle'
],
$user
[
'email'
],
$user
[
'emailcode'
]);
$sentusers
++
;
}
qa_opt
(
'mailing_last_timestamp'
,
$lasttime
+
$sentusers
*
60
/
$perminute
);
// can be floating point result, based on number of mails actually sent
}
else
{
qa_mailing_stop
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment