null 値の回避によるパフォーマンスの改善
SOQL および SOSL クエリでは、WHERE 句で明示的に null 値を除外することで、クエリのパフォーマンスを向上させることができます。次の例では、Thread__c の値が null であるすべてのレコードが検索から除外されます。
1Public class TagWS {
2
3/* getThreadTags
4*
5* a quick method to pull tags not in the existing list
6*
7*/
8 public static webservice List<String>
9 getThreadTags(String threadId, List<String> tags) {
10
11 system.debug(LoggingLevel.Debug,tags);
12
13 List<String> retVals = new List<String>();
14 Set<String> tagSet = new Set<String>();
15 Set<String> origTagSet = new Set<String>();
16 origTagSet.addAll(tags);
17
18// Note WHERE clause optimizes search where Thread__c is not null
19
20 for(CSO_CaseThread_Tag__c t :
21 [SELECT Name FROM CSO_CaseThread_Tag__c
22 WHERE Thread__c = :threadId AND
23 Thread__c != null])
24
25 {
26 tagSet.add(t.Name);
27 }
28 for(String x : origTagSet) {
29 // return a minus version of it so the UI knows to clear it
30 if(!tagSet.contains(x)) retVals.add('-' + x);
31 }
32 for(String x : tagSet) {
33 // return a plus version so the UI knows it's new
34 if(!origTagSet.contains(x)) retvals.add('+' + x);
35 }
36
37 return retVals;
38 }
39}