#114 Simplify and speed up current siteconfig lookup

Closed Simon Erkelens Firesphere

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 1 of 1 files from the diff.

@@ -70,6 +70,8 @@
Loading
70 70
        'CMS_ACCESS_LeftAndMain'
71 71
    ];
72 72
73 +
    private static $current_siteconfig;
74 +
73 75
    public function populateDefaults()
74 76
    {
75 77
        $this->Title = _t(self::class . '.SITENAMEDEFAULT', "Your Site Name");
@@ -269,13 +271,15 @@
Loading
269 271
     */
270 272
    public static function current_site_config()
271 273
    {
272 -
        /** @var SiteConfig $siteConfig */
273 -
        $siteConfig = DataObject::get_one(SiteConfig::class);
274 -
        if ($siteConfig) {
275 -
            return $siteConfig;
274 +
        if (!static::$current_siteconfig) {
275 +
            /** @var SiteConfig $siteConfig */
276 +
            static::$current_siteconfig = SiteConfig::get()->first();
277 +
            if (!static::$current_siteconfig) {
278 +
                self::make_site_config();
279 +
            }
276 280
        }
277 281
278 -
        return self::make_site_config();
282 +
        return static::$current_siteconfig;
279 283
    }
280 284
281 285
    /**
@@ -301,10 +305,8 @@
Loading
301 305
     */
302 306
    public static function make_site_config()
303 307
    {
304 -
        $config = SiteConfig::create();
305 -
        $config->write();
306 -
307 -
        return $config;
308 +
        self::$current_siteconfig = SiteConfig::create();
309 +
        self::$current_siteconfig->write();
308 310
    }
309 311
310 312
    /**

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Complexity Coverage
code ø 21.34%
Project Totals (3 files) 73 21.34%
Loading