Skip to content

Commit

Permalink
Change cache key for aliases. Related to #571
Browse files Browse the repository at this point in the history
  • Loading branch information
FCO committed Feb 25, 2024
1 parent d507b3d commit 4123910
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/MetamodelX/Red/Model.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ multi method join(\model, \to-join, $on where *.^can("relationship-ast"), :$name

my UInt $alias_num = 1;
method alias(|c (Red::Model:U \type, Str $name = "{type.^name}_{$alias_num++}", :$base, :$relationship, :$join-type, Bool :$opposite)) {
my $cache-key = c.WHICH;
$!alias-cache-lock.protect: {
return %!alias-cache{$name} if %!alias-cache{$name}:exists;
return %!alias-cache{$cache-key} if %!alias-cache{$cache-key}:exists;
my \alias = ::?CLASS.new_type(:$name);

my role RAlias[Red::Model:U \rtype, Str $rname, \alias, \rel, \base, \join-type, @cols] {
Expand Down Expand Up @@ -312,7 +313,7 @@ method alias(|c (Red::Model:U \type, Str $name = "{type.^name}_{$alias_num++}",
alias.^add-relationship: $rel.transfer: alias
}
alias.^compose;
%!alias-cache{$name} = alias;
%!alias-cache{$cache-key} = alias;

return alias;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Red/ResultSeq.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ multi method join-model(Red::Model \model, &on, :$name = "{ self.^shortname }_{
}
model.^all.where: $filter
} else {
self.of.^join(model, &on, :$name, |%pars).^all.clone: :$!chain
self.of.^join(model, &on, :$name, |%pars).^all.clone: :$!chain
}
}

Expand Down

0 comments on commit 4123910

Please sign in to comment.