Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit b5185b6

Browse files
committed
Cache ref index on load, use cache for calls
1 parent c60366d commit b5185b6

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

SalesforceReference.py

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""SublimeSalesforceReference: Quick access to Salesforce Documentation from Sublime Text"""
2-
__version__ = "1.1.1"
2+
__version__ = "1.2.0"
33
__author__ = "James Hill (oblongmana@gmail.com)"
44
__copyright__ = "SublimeSalesforceReference: (C) 2014 James Hill. GNU GPL 3."
55
__credits__ = ["All Salesforce Documentation is © Copyright 2000–2014 salesforce.com, inc.", "ThreadProgress.py is under the MIT License, Will Bond <will@wbond.net>, and SalesforceReference.py's RetrieveIndexThread method is a derives in part from code under the same license"]
@@ -11,10 +11,18 @@
1111
import threading
1212
from .ThreadProgress import ThreadProgress
1313

14-
# def plugin_loaded():
15-
# thread = RetrieveIndexThread(sublime.active_window())
16-
# thread.start()
17-
# ThreadProgress(thread, 'Retrieving Salesforce Reference Index...', '')
14+
class SalesforceReferenceCache():
15+
def __init__(self):
16+
self.sf_ref_pages_titles = []
17+
self.sf_ref_pages_links = []
18+
19+
reference_cache = SalesforceReferenceCache()
20+
21+
def plugin_loaded():
22+
thread = RetrieveIndexThread(sublime.active_window(),False)
23+
thread.start()
24+
ThreadProgress(thread, 'Retrieving Salesforce Reference Index...', '')
25+
1826

1927
class SalesforceReferenceCommand(sublime_plugin.WindowCommand):
2028

@@ -26,32 +34,38 @@ def run(self):
2634

2735
class RetrieveIndexThread(threading.Thread):
2836
"""
29-
A thread to run retrieval of the Saleforce Documentation induex
37+
A thread to run retrieval of the Saleforce Documentation index, or access the reference_cache
3038
"""
3139

32-
def __init__(self, window):
40+
def __init__(self, window, open_when_done=True):
3341
"""
3442
:param window:
3543
An instance of :class:`sublime.Window` that represents the Sublime
3644
Text window to show the available package list in.
45+
:param open_when_done:
46+
Whether this thread is being run solely for caching, or should open
47+
the documentation list for user selection when done. Defaults to
48+
true - should open the documentaton list when done
3749
"""
3850

3951
self.window = window
52+
self.open_when_done = open_when_done
53+
global reference_cache
4054
threading.Thread.__init__(self)
4155

56+
def run(self):
57+
if not (reference_cache.sf_ref_pages_titles and reference_cache.sf_ref_pages_links):
58+
sf_xml = urllib.request.urlopen('http://www.salesforce.com/us/developer/docs/apexcode/Data/Toc.xml').read().decode('utf-8')
59+
sf_tree = ElementTree.fromstring(sf_xml)
60+
leaf_parents = sf_tree.findall("*[@Title='Reference'].//TocEntry[@DescendantCount='0']..")
61+
for parent in leaf_parents:
62+
reference_cache.sf_ref_pages_titles.append(parent.attrib['Title'])
63+
reference_cache.sf_ref_pages_links.append(parent.attrib['Link'])
64+
65+
if(self.open_when_done):
66+
self.window.show_quick_panel(reference_cache.sf_ref_pages_titles, self.open_documentation)
67+
4268
def open_documentation(self, reference_index):
4369
if(reference_index != -1):
4470
base_url= 'http://www.salesforce.com/us/developer/docs/apexcode'
45-
webbrowser.open_new_tab(base_url + self.sf_ref_pages_links[reference_index])
46-
47-
def run(self):
48-
sf_xml = urllib.request.urlopen('http://www.salesforce.com/us/developer/docs/apexcode/Data/Toc.xml').read().decode('utf-8')
49-
sf_tree = ElementTree.fromstring(sf_xml)
50-
leaf_parents = sf_tree.findall("*[@Title='Reference'].//TocEntry[@DescendantCount='0']..")
51-
self.sf_ref_pages_titles = []
52-
self.sf_ref_pages_links = []
53-
for parent in leaf_parents:
54-
self.sf_ref_pages_titles.append(parent.attrib['Title'])
55-
self.sf_ref_pages_links.append(parent.attrib['Link'])
56-
57-
self.window.show_quick_panel(self.sf_ref_pages_titles, self.open_documentation)
71+
webbrowser.open_new_tab(base_url + reference_cache.sf_ref_pages_links[reference_index])

messages.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"1.0.0": "messages/1.0.0.txt",
44
"1.0.1": "messages/1.0.1.txt",
55
"1.1.0": "messages/1.1.0.txt",
6-
"1.1.1": "messages/1.1.1.txt"
6+
"1.1.1": "messages/1.1.1.txt",
7+
"1.2.0": "messages/1.2.0.txt"
78
}

messages/1.2.0.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Sublime Salesforce Reference 1.2.0 Release Notes:
2+
3+
Enhancements:
4+
- Salesforce Reference index is now cached when the plugin loads, or if the cache is otherwise empty for some reason. As such, successive calls to the reference command should happen without delay, instead of calling out each time!

0 commit comments

Comments
 (0)