Skip to content

Commit

Permalink
Skip tracking affected relations and concepts for RELATION lastAccess…
Browse files Browse the repository at this point in the history
…[SESSION*DateTime]
  • Loading branch information
Michiel-s committed Apr 26, 2024
1 parent ef1ed50 commit ec430c1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Additional labels for pre-release and build metadata are available as extensions

## Unreleased changes
* [Issue 79](https://github.com/AmpersandTarski/prototype/issues/79) Add support for delimited multi value columns in excel importer
* Skip tracking affected relations and concepts for RELATION lastAccess[SESSION*DateTime]
* Add codebase of new developed frontend. Not integrated in building image yet.

## v1.17.0 (24 may 2023)
Expand Down
4 changes: 2 additions & 2 deletions src/Ampersand/Core/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ public function getSmallest(): Atom
/**
* Add atom to concept
*/
public function add(bool $populateDefaults = true): self
public function add(bool $populateDefaults = true, bool $trackAffected = true): self
{
$this->concept->addAtom($this, $populateDefaults);
$this->concept->addAtom($this, $populateDefaults, $trackAffected);
return $this;
}

Expand Down
10 changes: 7 additions & 3 deletions src/Ampersand/Core/Concept.php
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ public function makeAtom(string $atomId): Atom
*
* @param bool $populateDefaults specifies if default src/tgt values for relations must be populated also
*/
public function addAtom(Atom $atom, bool $populateDefaults = true): Atom
public function addAtom(Atom $atom, bool $populateDefaults = true, bool $trackAffected = true): Atom
{
// Adding atom[A] to [A] ($this)
if ($atom->concept === $this) {
Expand All @@ -553,7 +553,11 @@ public function addAtom(Atom $atom, bool $populateDefaults = true): Atom
} else {
$this->logger->debug("Add atom {$atom} to plug");
$transaction = $this->app->getCurrentTransaction();
$transaction->addAffectedConcept($this); // Add concept to affected concepts. Needed for conjunct evaluation and transaction management

if ($trackAffected) {
// Add concept to affected concepts. Needed for conjunct evaluation and transaction management
$transaction->addAffectedConcept($this);
}

foreach ($this->getPlugs() as $plug) {
$plug->addAtom($atom); // Add to plug
Expand Down Expand Up @@ -583,7 +587,7 @@ public function addAtom(Atom $atom, bool $populateDefaults = true): Atom
}

$atom->concept = $this; // Change concept definition
return $this->addAtom($atom, false);
return $this->addAtom($atom, false, $trackAffected);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ampersand/Core/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ public function exists(): bool
/**
* Add link relation set
*/
public function add(): self
public function add(bool $trackAffected = true): self
{
$this->rel->addLink($this);
$this->rel->addLink($this, $trackAffected);
return $this;
}

Expand Down
12 changes: 8 additions & 4 deletions src/Ampersand/Core/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,19 @@ public function getAllLinks(?Atom $srcAtom = null, ?Atom $tgtAtom = null): array
/**
* Add link to this relation
*/
public function addLink(Link $link): void
public function addLink(Link $link, bool $trackAffected = true): void
{
$this->logger->debug("Add link {$link} to plug");
$transaction = $this->app->getCurrentTransaction();
$transaction->addAffectedRelations($this); // Add relation to affected relations. Needed for conjunct evaluation and transaction management

if ($trackAffected) {
// Add relation to affected relations. Needed for conjunct evaluation and transaction management
$transaction->addAffectedRelations($this);
}

// Ensure that atoms exist in their concept tables
$link->src()->add(false); // TODO: remove when we know for sure that this is guaranteed by calling functions
$link->tgt()->add(false); // TODO: remove when we know for sure that this is guaranteed by calling functions
$link->src()->add(false, $trackAffected); // TODO: remove when we know for sure that this is guaranteed by calling functions
$link->tgt()->add(false, $trackAffected); // TODO: remove when we know for sure that this is guaranteed by calling functions

foreach ($this->getPlugs() as $plug) {
$plug->addLink($link);
Expand Down
5 changes: 4 additions & 1 deletion src/Ampersand/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,10 @@ public function initSessionAtom(): void
// $_SESSION['lastAccess'] = $now;

// Update lastAccess time also in plug/database to allow to use this aspect in Ampersand models
$this->sessionAtom->link(date(DATE_ATOM, $now), 'lastAccess[SESSION*DateTime]', false)->add();
// We set 'trackAffected' to false for this relation, because it will significantly reduce the rule evaluation overhead
// for every session interaction. We can safely do this, because no new Session atom is implicitly created here nor does
// the DateTime atom is reused elsewhere
$this->sessionAtom->link(date(DATE_ATOM, $now), 'lastAccess[SESSION*DateTime]', false)->add(trackAffected: false);
}

/**
Expand Down

0 comments on commit ec430c1

Please sign in to comment.