CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Global User Object
Pages: [1]

Author Topic: Global User Object  (Read 3154 times)

chrisivens

  • Guest
Global User Object
March 25, 2009, 03:21:25 am
Just as in drupal you have access to the $user object, is there or can we have a user object for the currently logged in user. That way it can be cached and things like membership info can be stored and easily retrieved without db access too much. The amount of times I have had to query the db for membership is excessive I think.

I suggest using the Proxy design pattern to act as a gateway between a Singleton user object which can retrieve the cached data from the session and load it lazily into the user object.

I might even write this myself as it would make my custom code much quicker.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Global User Object
March 25, 2009, 06:51:18 am

the core does not use user state a lot and hence we have not cached the user object (and stuff like membership info)

other than membership info (which should definitely be cached), what other potential things can/should we cache (i assume basic contact info also, name, address, email etc)

a good project for 2.3 :)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

chrisivens

  • Guest
Re: Global User Object
March 25, 2009, 07:13:26 am
I think if we do it right it will not have too much impact on processing time. Only when things are requested from the proxy do we get the data from the db. This means that when it is stored in the session, we check the user object for the value first. If not in the user object we then check the session and failing that we get from db.

Thinking about it though, this could even be extended as a way to access contact info in general. A potential way of allowing devs to get the data they need without trawling through the core files. I'm getting all excited about this.

Logged in user could be cached in session but the proxy for other users could be discarded each cycle.

Things that can be fetched/cached:
membership
contact info (basic)
email-primary
last login (not needed for logged in user but might be useful for other contacts)
maybe waiting list info
last contacted (part of activities)

I know it's easy to get carried away but I see no reason why not to. Also if it is a nice system it should be easy to extend the proxy and the user object to fetch more. It would make it easier for contrib devs too. If need be, the proxy and the user object could be extended by using the decorator pattern which means functionality could be bolted together to get whatever is needed.

Perhaps something of this sort could be extended into a new api system. I know the api has a lot to do with the rest api too but if the api and the core code are all using the same thing then nothing gets left behind.

Opinions and corrections always welcome of course.

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Global User Object
March 26, 2009, 09:19:40 am
I'd add the tags & groups of the user.

Are all these user/session info going to be assigned to the templates (oh yes they should can I hear myself answering) ?

At least for the interactive user (ie not the user on cli/rest interface), loading that at the login doesn't seem to be a performance impact, and most will be needed anyway if we want to implement "real" ACLs.

X+

-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Global User Object

This forum was archived on 2017-11-26.