We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Saving vars as files

Developer Preview

Low's avatar
Low
407 posts
9 years ago
Low's avatar Low

Can someone explain the flow of syncing the snippets/global_vars to me? I’m curious to see if this will affect Low Variables in some way or another. Thanks.

       
Low's avatar
Low
407 posts
9 years ago
Low's avatar Low

Also because I’m now seeing a lot of extra queries per page load on the front end, all updates to the global_variables table, one for each variable or snippet (even with LV disabled, so that doesn’t interfere).

Is this going to be scalable?

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
9 years ago
Pascal Kriete's avatar Pascal Kriete

Sure thing, Low.

The general pseudo-code logic is the same as for templates:

$row = $db->get($name);
$file = $fs->get($name);

if ( ! $row && ! $file)
{
    return NULL;
}

if ( ! $file || $file->edit_date < $row->edit_date)
{
    write_to_file($row);
}

if ( ! $row || $file->edit_date > $row->edit_date)
{
    insert_or_update_row_with($file);
}

return $row;

This runs whenever a model entity is retrieved. There’s a special getAll() method on those models which grabs all db rows and then scans the directory for new files and adds them to the result collection. That method is used on the frontend request to fetch all snippets/gvs and on the cp listing pages.

Otherwise we use the models as usual - there is no way to retrieve one of these models without getting the latest data. When saving we update the file and the row, if necessary. And lastly, deleting the model also deletes the file (the reverse is not true).

Hope that helps!

       
Pascal Kriete's avatar
Pascal Kriete
2,589 posts
9 years ago
Pascal Kriete's avatar Pascal Kriete

Looking into those queries - that shouldn’t be happening.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.