Big informatization standard basic data management platform


The actual situation:

     1: When the site visits, hundreds of thousands of IP per day, The web server's pressure is very big, A very simple procedure, 2 SQL statements are adjacent, in the server is busy, may have to run after 3-5 minutes, or even longer. Server hardware configuration have been high enough, it is almost impossible to rely on normal read and write the database, database optimization to improve program performance.

     2: Hard drive speed is limited, When the database is large, the database also spend a lot of time. But with hard disk is relatively more complicated than memory.

    3: When the database index optimization, partitioning optimization have been exhausted, the structure of the database can not change, By database optimization is experiencing a bottleneck..

    4: NowMemory is cheap, The server can insert memory space can be filled, but often do not spend all the memory, the memory space can be helpful.

    5: Although it can be used in many third party components to achieve the purpose of optimization, but need to haveThe learning cost, purchasing cost, maintenance cost again later, The performance of the server is also increasing pressure.

    6: At present, the serverPressure has been quickly collapsed, It's difficult to improve performance, more complex permissions calculation, each refresh a page, also judged 10 times 8 times operation permission project, need more I/O, it is likely that the system would collapse.

    7: Of course we can buy another server, the procedures of pressure to share, but we assume that don't buy hardware., The database must also need to use the same, read data from the same server database needs.


In the above program environment, is the old fogey also need to change the thinking.

  1: Old fogey are more difficult to change the thought:

       Because the truth is, stubborn old must also accept the cache approach, although cache sometimes excruciating, has been difficult to solve the problem but not by the cache. Although there are many people gave me this advice, don't put in the mind.


  2: Change the program time thinking:

      Previously written procedures are emphasized, the data set changed program can show up immediately, such as modifying someone permission settings, will soon come into force. In fact, sometimes not necessary so immediately. Refresh cache when necessary, if not will come into effect next time you login to the user, at most, if there is a problem of user login again once, permissions settings are not always in settings, often set up, half a year are not set, no need to over emphasize the real-time.

     In fact, programmers have excessive design, user rights, I do think some excessive, actually slightly relaxed, also can meet the normal daily use, can add a refreshing the cache function, if necessary, effective immediately immediately scrub the cache can be.


3: No increase in the times, as many young people completely beyond the:

Obviously feel young and smart and capable, now you don't improve, very easy to completely downhill. Although difficult to play a leading role, but at least not being completely left behind to go.


  4: It immediately improvement program:

    The idea is to do it immediately, before the good structure withstand reconstruction program, so that they have been in the program structure is very good, it should be able to withstand changes to the architecture, good program should not completely knocked down ever, but small modification function should be able to achieve the purpose of the in memory cache.


  5: The new system should be reliable on-line test confirmation:

    Program updating it, at least 1 weeks before and after the test, all kinds of features are stable, the data are correct to formally put into practical reality.


    Auspicious Gala, universal privilege management system components


Then is the part of the program revision:

      In fact, a total of about 300 lines of code is not to reform system, the essence of the completed.

      1: Module menu users can access permissions, user owned, improvement to the generic.

          protected List<BaseModuleEntity> ModuleList

          protected List<BasePermissionItemEntity> PermissionItemList

      2: When the user needs to determine the permissions, one-time permissions to read into the Cache cache.

       3: The authority to determine the function improvement for judging from the memory Cache cache.

      4: User exit, remove the memory cache corresponding, reducing memory pressure.

      5: Write a refresh buffer function, when necessary, to all the cache for real-time refresh.


      Sometimes the code is less than 300 lines and a pile of notes, there are a lot of no use, there are a lot of repeat, the real value of the code may not be more than 50 lines, but there are quite a lot of stories, stories of the code more vitality, stories of the code are more selling points, there is the story of code is often more amenable, welcome everybody clap brick, everyone together to improve learning, in communication constantly revised code, and constantly improve themselves, improve error, stronger every day.


Copy code
  1 //-----------------------------------------------------------------
  2 // All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd .
  3 //-----------------------------------------------------------------
  4
  5 using System;
  6 using System.Collections.Generic;
  7 using System.Linq;
  8 using System.Web;
  9
10 using DotNet.Business;
11
12 /// <remarks>
13 /// BasePage
14 /// Class based webpage
15 ///
16 /// Amendment record
17 ///
18 ///    Edition: 1.0 2012.11.10    JiRiGaLa    Finishing the code.
19 ///   
20 /// Edition: 1.0
21 /// <author> 
22 ///        <name>JiRiGaLa</name>
23 ///        <date>2012.11.10</date>
24 /// </author>
25 /// </remarks>
26 public partial class BasePage : System.Web.UI.Page
27 {
28     /// <summary>
29     /// The user lock
30     /// </summary>
31     public static readonly object UserLock = new object();
32
33     #Region commonly used operation authority Xiang Dingyi
34
35     /// <summary>
36     /// Access authority
37     /// </summary>
38     protected bool permissionAccess = true;
39
40     /// <summary>
41     /// Additional permissions
42     /// </summary>
43     protected bool permissionAdd = true;
44
45     /// <summary>
46     /// Edit permissions
47     /// </summary>
48     protected bool permissionEdit = true;
49
50     /// <summary>
51     /// Delete permissions
52     /// </summary>
53     protected bool permissionDelete = true;
54
55     /// <summary>
56     /// Inquiry authority
57     /// </summary>
58     protected bool permissionSearch = true;
59
60     /// <summary>
61     /// Management authority
62     /// </summary>
63     protected bool permissionAdmin = false;
64
65     /// <summary>
66     /// Export permission
67     /// </summary>
68     protected bool permissionExport = true;
69
70     /// <summary>
71     /// Import permission
72     /// </summary>
73     protected bool permissionImport = true;
74
75     /// <summary>
76     /// Print permissions
77     /// </summary>
78     protected bool permissionPrint = true;
79
80     #endregion
81    
82     // If the user in a role (by number, by name)
83
84     #region public bool UserIsInRole(string roleCode)
85     /// <summary>
86     /// If the user in a role.
87     /// </summary>
88     /// <param name="roleCode">Part number</param>
89     /// <returns>Whether in a role.</returns>
90     public bool UserIsInRole(string roleCode)
91     {
92         BaseUserManager userManager = new BaseUserManager(this.UserCenterDbHelper, userInfo);
93         return userManager.IsInRoleByCode(this.UserInfo.Id, roleCode);
94     }
95     #endregion
96    
97     // Users access to common judgment function
98
99     #region public void Authorized(string permissionItemCode, string accessDenyUrl = null) If there is a corresponding authority, at the same time without permission will be redirected to a page
100     /// <summary>
101     /// If there is a corresponding authority, at the same time without permission will be redirected to a page
102     /// </summary>
103     /// <param name="permissionItemCode">Access numbers</param>
104     /// <param name="accessDenyUrl">Access denied to URL</param>
105     public void Authorized(string permissionItemCode, string accessDenyUrl = null)
106     {
107         // If does not have the appropriate permissions, then jump to the page without permission
108         if (!Utilities.UserIsLogOn() || !IsAuthorized(permissionItemCode))
109         {
110             if (!string.IsNullOrEmpty(accessDenyUrl))
111             {
112                 HttpContext.Current.Response.Redirect(accessDenyUrl);
113             }
114             else
115             {
116                 HttpContext.Current.Response.Redirect(Utilities.AccessDenyPage + "?PermissionItemCode=" + permissionItemCode);
117             }
118         }
119     }
120     #endregion
121
122     #region public bool IsAuthorized(string permissionItemCode, string permissionItemName = null) Whether have the corresponding rights
123     /// <summary>
124     /// Whether have the corresponding rights
125     /// </summary>
126     /// <param name="permissionItemCode">Access numbers</param>
127     /// <returns>You have permission to</returns>
128     public bool IsAuthorized(string permissionItemCode, string permissionItemName = null)
129     {
130         return IsAuthorized(this.UserInfo.Id, permissionItemCode, permissionItemName);
131     }
132
133     public bool IsAuthorized(string userId, string permissionItemCode, string permissionItemName = null)
134     {
135         // Whether to read the user permissions from the server cache
136         bool fromCache = true;
137         if (fromCache)
138         {
139             // It can also optimize the look, list all permissions need not traverse
140             int count = this.PermissionItemList.Count(entity => !string.IsNullOrEmpty(entity.Code) && entity.Code.Equals(permissionItemCode, StringComparison.OrdinalIgnoreCase));
141             return count > 0;
142         }
143         // Setting method of real-time read permissions from the database
144         DotNetService dotNetService = new DotNetService();
145         return dotNetService.PermissionService.IsAuthorizedByUser(this.UserInfo, userId, permissionItemCode, permissionItemName);
146     }
147     #endregion
148
149     #region protected void GetPermissionItemList() The user has the permissions list
150     /// <summary>
151     /// The user has the permissions list
152     /// </summary>
153     protected void GetPermissionItemList()
154     {
155         // Here is the control of concurrent users, efficiency reduce frame repeat access database
156         lock (BasePage.UserLock)
157         {
158             string cacheKey = "P" + this.UserInfo.Id;
159             if (HttpContext.Current.Session == null || Cache[cacheKey] == null)
160             {
161                 // This is the default system table name
162                 DotNetService dotNetService = new DotNetService();
163                 PermissionItemList = dotNetService.PermissionService.GetPermissionItemListByUser(this.UserInfo, this.UserInfo.Id);
164             }
165         }
166     }
167     #endregion
168
169     #region protected List<BasePermissionItemEntity> PermissionItemList won the user has permissions list
170     /// <summary>
171     /// The user has the permissions list
172     /// </summary>
173     protected List<BasePermissionItemEntity> PermissionItemList
174     {
175         get
176         {
177             lock (BasePage.UserLock)
178             {
179                 // Here are optimized operation authority, error problem
180                 this.GetPermissionItemList();
181             }
182             string cacheKey = "P" + this.UserInfo.Id;
183             return Cache[cacheKey] as List<BasePermissionItemEntity>;
184         }
185         set
186         {
187             string cacheKey = "P" + this.UserInfo.Id;
188             Cache[cacheKey] = value;
189         }
190     }
191     #endregion
192    
193     // The user module menu authority to determine the common function
194
195     #region public void ModuleAuthorized(string moduleCode, string accessDenyUrl = null) If there are modules corresponding to the rights, at the same time without permission will be redirected to a page
196     /// <summary>
197     /// If there are modules corresponding to the rights, at the same time without permission will be redirected to a page
198     /// </summary>
199     /// <param name="moduleCode">Module number</param>
200     /// <param name="accessDenyUrl">Access denied to URL</param>
201     public void ModuleAuthorized(string moduleCode, string accessDenyUrl = null)
202     {
203         // If does not have the appropriate permissions, then jump to the page without permission
204         if (!Utilities.UserIsLogOn() || !IsModuleAuthorized(moduleCode))
205         {
206             if (!string.IsNullOrEmpty(accessDenyUrl))
207             {
208                 HttpContext.Current.Response.Redirect(accessDenyUrl);
209             }
210             else
211             {
212                 HttpContext.Current.Response.Redirect(Utilities.AccessDenyPage + "?ModuleCode=" + moduleCode);
213             }
214         }
215     }
216     #endregion
217
218     #region public bool IsModuleAuthorized(string moduleCode) If there are modules corresponding to the rights
219     /// <summary>
220     /// If there are modules corresponding to the rights
221     /// </summary>
222     /// <param name="moduleCode">Module number</param>
223     /// <returns>You have permission to</returns>
224     public bool IsModuleAuthorized(string moduleCode)
225     {
226         if (this.UserInfo.IsAdministrator)
227         {
228             return true;
229         }
230         // It can also optimize the look, module list all unnecessary traversal
231         int count = this.ModuleList.Count(entity => !string.IsNullOrEmpty(entity.Code) && entity.Code.Equals(moduleCode, StringComparison.OrdinalIgnoreCase));
232         return count > 0;
233     }
234     #endregion
235
236     #region protected void GetModuleList() List of modules by users have access to
237     /// <summary>
238     /// List of modules by users have access to
239     /// </summary>
240     protected void GetModuleList()
241     {
242         // Here is the control of concurrent users, efficiency reduce frame repeat access database
243         lock (BasePage.UserLock)
244         {
245             string cacheKey = "M" + this.UserInfo.Id;
246             if (HttpContext.Current.Session == null || Cache[cacheKey] == null)
247             {
248                 // This is the default system table name
249                 DotNetService dotNetService = new DotNetService();
250                 ModuleList = dotNetService.PermissionService.GetModuleListByUser(this.UserInfo, this.UserInfo.Id);
251             }
252         }
253     }
254     #endregion
255
256     #region protected List<BaseModuleEntity> List of modules by users have access to ModuleList
257     /// <summary>
258     /// List of modules by users have access to
259     /// </summary>
260     protected List<BaseModuleEntity> ModuleList
261     {
262         get
263         {
264             lock (BasePage.UserLock)
265             {
266                 // Here is the menu optimization, error problem
267                 this.GetModuleList();
268             }
269             string cacheKey = "M" + this.UserInfo.Id;
270             // return Utilities.GetFromSession("UserModuleList") as List<BaseModuleEntity>;
271             return Cache[cacheKey] as List<BaseModuleEntity>;
272         }
273         set
274         {
275             string cacheKey = "M" + this.UserInfo.Id;
276             Cache[cacheKey] = value;
277             // Utilities.AddSession("UserModuleList", value);
278         }
279     }
280     #endregion
281 }
Copy code


The permissions management, workflow management do my ability to the ultimate, a person can only do so few things.

Posted by Allen at November 24, 2013 - 3:22 PM