Hi, I've been using SQL filters on DataDictionaries for a while and they are great! However, I would like to improve my code and optimize even more the loading time. Here is the situation:
I use SQL filters (psSQLFilter with pbUseDDSQLFilters enabled) in some DataDictionaries to filter data based on user rights (defined on other tables).
Basically, in those DDs I call a function which returns the SQL string ready for the psSQLFilter proprety inside the OnConstrain event. The problem is, this function is called a lot of times each time the view/lookup is loaded or cleared, and it needs to do some tasks in order to generate that (find operations), it is not a simple "return <my static filter>" function.
So the question is, where should I call that function and set the psSQLFilter property so that it gets called the minimum amount of times? It would be ideal if it would get set during OnChangeRights event of the WebApp or even OnBeforeShow, but I guess it is too complicated (and it would imply tweaking in each view those DDs are used).

Another issue, I know psSQLFilters are only applied to the main DataDictionary of the structure, so this wouldn't work if the server is another DataDictionary. As I need to apply those filters in every place where those DD are used (it is defined in the DD class), I need to keep in those DDs both the code for the filters and the classic Constrain DF code in the DD class. It would be great if those SQL filters were inherited from parent DD, I know this is a framework limitation. Is there something I can do here to avoid problems? I have optimized it so that the function which generates the filter doesn't get called when the DD is not the main one (it wouldn't be applied anyways).

Perhaps the framework is not designed to do this, do you have experience with this kind of situation?
Thank you very much