Browse Source

Don't factor in seconds when filtering live entries (again)

Re-resolves #5389, w/o breaking #7853 by locking the time in at 59 seconds instead of 00.
pull/11385/head
brandonkelly 3 years ago
parent
commit
2921fa5365
No known key found for this signature in database GPG Key ID: 5E86D0CED64C7093
  1. 1
      CHANGELOG.md
  2. 8
      src/elements/db/EntryQuery.php

1
CHANGELOG.md

@ -5,6 +5,7 @@
### Changed
- Read/write splitting is now disabled for all console requests.
- The `db/restore` command now prompts to clear data caches after the import is complete. ([#11327](https://github.com/craftcms/cms/issues/11327))
- Entry queries no longer factor in seconds when looking for currently-live entries, without excluding entries that were published in the past minute. ([#5389](https://github.com/craftcms/cms/issues/5389))
### Fixed
- Fixed an error that could occur on PHP 8.1. ([#11345](https://github.com/craftcms/cms/pull/11345))

8
src/elements/db/EntryQuery.php

@ -18,6 +18,7 @@ use craft\helpers\StringHelper;
use craft\models\EntryType;
use craft\models\Section;
use craft\models\UserGroup;
use DateTime;
use yii\base\InvalidConfigException;
use yii\db\Connection;
@ -844,7 +845,12 @@ class EntryQuery extends ElementQuery
*/
protected function statusCondition(string $status)
{
$currentTimeDb = Db::prepareDateForDb(new \DateTime());
// Always consider “now” to be the current time @ 59 seconds into the minute.
// This makes entry queries more cacheable, since they only change once every minute (https://github.com/craftcms/cms/issues/5389),
// while not excluding any entries that may have just been published in the past minute (https://github.com/craftcms/cms/issues/7853).
$now = new DateTime();
$now->setTime((int)$now->format('H'), (int)$now->format('i'), 59);
$currentTimeDb = Db::prepareDateForDb($now);
switch ($status) {
case Entry::STATUS_LIVE:

Loading…
Cancel
Save