Hi again Chris, I have a few questions about ReadStrategies after playing around with them. Lets say my Players have an id which is an integer and a login which is a String. Setting minimumDepth: 0 gives me the id reified and a proxy for the login. But setting the min depth to 1 gives me the exact same thing. I need to set the depth to 2 to get the String. If that's normal what is the difference between 0 and 1?
Another thing. As you saw I have a Desk with letters which refers to other Players. I don't want theses players to be reified but I want object deeper to be. So I tried something like that : session readStrategy: ((MaReadStrategy minimumDepth: 1) onAny: Desk readToDepth: 0). But it didn't seem to work. This answers OrderedCollection : ((player instVarNamed: 'myDesk') instVarNamed: 'inbox') class. So how can I make the rule on Desk precedes the more global rule?
A very simple browser to go through the hierarchy to see what is reified and what isn't could be great :).
Florian
Chris Muller wrote:
First of all, how long will the read strategy last for a given session by doing mySession 'session readStrategy: myReadStrategy.' ?
It will last until you replace it with another ReadStrategy.
Do I have to revert it back to a default strategy after my specific queries ?
Yes. If you have a specific query you need to optimise by changing the depths of certain variables of certain classes, you will probably want to revert to your "default" strategy afterward, otherwise the specific-query strategy will continue to be used.
For example : my Players have a reference to a Dungeon which references a Desk which has two OrderedCollection referencing Letters. If I want to send a Letter to 10 Players, I need to had a Letter in each of their Desk, resulting of a huge query I think. Is there a way to be so much specific with a ReadStrategy ?
Let's see here.
Player --->(1) Dungeon --->(1) Desk --->(*) Letter
So, for this operation (sending a single Letter to 10 Players), use a ReadStrategy, something like this:
(myReadStrategy minimumDepth: 1) forVariableNamed: 'dungeon' onAny: Player readToDepth: 1 ; forVariableNamed: 'desk' onAny: Dungeon readToDepth: 1 ; forVariableNamed: 'letters1' onAny: Desk readToDepth: 2 ; forVariableNamed: 'letters2' onAny: Desk readToDepth: 2.
This will cause the Player-->Dungeon-->Desk-->OC of Letters to be grabbed in a single server-trip.
The 'letters1' OC species 2 levels because there is the intermediate 'array' variable.. But you'll have to experiment to get it fully optimised. The way to do this is be careful opening inspectors, because clicking the instVars inspectors invokes #printString causes proxy materializations. So what you do is just open the *inspector* (NOT an explorer) on your Desk and ask the instVar for its class before inspecting it:
letters1 class "MagmaMutatingProxy"
then you know you need one level deeper, because you want it to say "OrderedCollection". When you fix the ReadStrategy to do that, try it again but still do NOT click on the 'letters1' variable because the inspector will try to enumerate the values. Instead:
letters1 basicInspect
and then, in the basic-inspector:
array class "Array" or "MagmaMutatingProxy"
and so on.
In this way you can see exactly how it works and, knowing what you need, be able to craft a fully-optimised ReadStrategy for each use-case.
Regards, Chris