[autotest] Stops rpc get_static_data from fetching cros- and fw-version labels.

Both the rpc interface get_static_data and afe pages loads slow as they need
to read all 60000+ labels. From a user friendly perspective, it's not easy to
find a desired label from this long list on afe.

This will leave only 188 labels. The afe page load time is reduced from 10s to
less than 1s, and the db query time was reduced from 2.37s to 0.07s (both
tested on my local machine with a dump prod db copy).

BUG=chromium:368308
DEPLOY=apache
TEST=ran afe, ran Create Job and Host List tab, selected label from label list

Change-Id: Ifd0e8bc91b2cce8e453f93eec94bb132c2442744
Reviewed-on: https://chromium-review.googlesource.com/203444
Tested-by: Jiaxi Luo <jiaxiluo@chromium.org>
Reviewed-by: Simran Basi <sbasi@chromium.org>
Commit-Queue: Jiaxi Luo <jiaxiluo@chromium.org>
diff --git a/frontend/afe/rpc_interface.py b/frontend/afe/rpc_interface.py
index 80e2197..84c5fae 100644
--- a/frontend/afe/rpc_interface.py
+++ b/frontend/afe/rpc_interface.py
@@ -77,13 +77,16 @@
     models.Label.smart_get(id).host_set.remove(*host_objs)
 
 
-def get_labels(**filter_data):
+def get_labels(exclude_filters=(), **filter_data):
     """\
+    @param exclude_filters: A sequence of dictionaries of filters.
+
     @returns A sequence of nested dictionaries of label information.
     """
-    return rpc_utils.prepare_rows_as_nested_dicts(
-            models.Label.query_objects(filter_data),
-            ('atomic_group',))
+    labels = models.Label.query_objects(filter_data)
+    for exclude_filter in exclude_filters:
+        labels = labels.exclude(**exclude_filter)
+    return rpc_utils.prepare_rows_as_nested_dicts(labels, ('atomic_group',))
 
 
 # atomic groups
@@ -884,7 +887,8 @@
     priorities: List of job priority choices.
     default_priority: Default priority value for new jobs.
     users: Sorted list of all users.
-    labels: Sorted list of all labels.
+    labels: Sorted list of labels not start with 'cros-version' and
+            'fw-version'.
     atomic_groups: Sorted list of all atomic groups.
     tests: Sorted list of all tests.
     profilers: Sorted list of all profilers.
@@ -893,7 +897,7 @@
     job_statuses: Sorted list of possible HostQueueEntry statuses.
     job_timeout_default: The default job timeout length in minutes.
     parse_failed_repair_default: Default value for the parse_failed_repair job
-    option.
+            option.
     reboot_before_options: A list of valid RebootBefore string enums.
     reboot_after_options: A list of valid RebootAfter string enums.
     motd: Server's message of the day.
@@ -914,7 +918,13 @@
     result['default_priority'] = 'Default'
     result['max_schedulable_priority'] = priorities.Priority.DEFAULT
     result['users'] = get_users(sort_by=['login'])
-    result['labels'] = get_labels(sort_by=['-platform', 'name'])
+
+    label_exclude_filters = [{'name__startswith': 'cros-version'},
+                             {'name__startswith': 'fw-version'}]
+    result['labels'] = get_labels(
+        label_exclude_filters,
+        sort_by=['-platform', 'name'])
+
     result['atomic_groups'] = get_atomic_groups(sort_by=['name'])
     result['tests'] = get_tests(sort_by=['name'])
     result['profilers'] = get_profilers(sort_by=['name'])