From: kenstir Date: Sat, 5 Dec 2015 02:44:47 +0000 (-0500) Subject: Not yet successful attempt to move biblio.record.copy_count out of main search. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b8bead74b8aa5c91daef80c9c49bb3c779afdf15;p=working%2FEvergreen.git Not yet successful attempt to move biblio.record.copy_count out of main search. That call is taking 30% of the total search time, and it is not even necessary until you look at the item details. Made sure that the orgID is properly passed from SearchCatalog through to BasicDetailsFragment. Not working yet because my first attempt was to call getCopyCount on the main thread. End goal: volley-based OSRF response handler. --- diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java index 2642509261..1c8c22fe89 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/accountAccess/bookbags/BookBagDetails.java @@ -178,14 +178,12 @@ public class BookBagDetails extends ActionBarActivity { @Override public void run() { - - ArrayList records = new ArrayList(); ArrayList ids = new ArrayList(); for (int i = 0; i < bookBag.items.size(); i++) { ids.add(bookBag.items.get(i).target_copy); } - records = search.getRecordsInfo(ids); + ArrayList records = search.getRecordsInfo(ids); for (int i = 0; i < bookBag.items.size(); i++) { bookBag.items.get(i).recordInfo = records.get(i); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/CopyInformation.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/CopyInformation.java index 9b7ad3a6ed..6561f189c8 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/CopyInformation.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/CopyInformation.java @@ -36,11 +36,8 @@ public class CopyInformation implements Serializable { private final String TAG = CopyInformation.class.getName(); public Integer org_id = -1; - public String call_number_sufix; - public String copy_location; - public HashMap statuses; // the hash from the request method @@ -63,20 +60,19 @@ public class CopyInformation implements Serializable { statusInformation = new LinkedHashMap(); Set> set = availableOrgStatuses.entrySet(); - Iterator> it = set.iterator(); - while (it.hasNext()) { Entry entry = it.next(); if (hashValCopy.containsKey(entry.getKey())) { statusInformation.put(entry.getValue(), hashValCopy.get(entry.getKey()) + ""); -// Log.d(TAG, "Added " + entry.getKey() + " " -// + entry.getValue() + " " -// + hashValCopy.get(entry.getKey())); +// Log.d(TAG, "Added " + entry.getKey() + " -> " +// + entry.getValue() + " (" +// + hashValCopy.get(entry.getKey()) + ")"); } } + Log.d(TAG, "done"); } } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/RecordInfo.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/RecordInfo.java index f3e07ed8fc..47a0c1238d 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/RecordInfo.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/RecordInfo.java @@ -39,7 +39,7 @@ public class RecordInfo implements Serializable { public String author = null; public String pubdate = null; public String isbn = null; - public Integer doc_id = null; + public Integer doc_id = -1; public String publisher = null; public String subject = ""; public String doc_type = null; @@ -50,15 +50,13 @@ public class RecordInfo implements Serializable { public boolean dummy = false; public ArrayList copyCountListInfo = null; - - public List copyInformationList = null; + public List copyInformationList = new ArrayList(); public String search_format = null; public RecordInfo() { this.title = "Test title"; this.author = "Test author"; this.pubdate = "Publication date"; - copyInformationList = new ArrayList(); // marks the fact that this is a record made from no info this.dummy = true; @@ -78,7 +76,6 @@ public class RecordInfo implements Serializable { } public RecordInfo(OSRFObject info) { - copyInformationList = new ArrayList(); try { this.title = safeString(info.getString("title")); this.author = safeString(info.getString("author")); diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java index 3a01916044..e3b71547ab 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SampleUnderlinesNoFade.java @@ -21,47 +21,32 @@ package org.evergreen_ils.searchCatalog; import java.util.ArrayList; -import android.support.v7.app.ActionBar; import android.view.MenuItem; import org.evergreen_ils.R; -import org.evergreen_ils.accountAccess.AccountAccess; import org.evergreen_ils.utils.ui.*; import org.evergreen_ils.views.splashscreen.SplashActivity; import android.app.ProgressDialog; import android.content.Context; import android.content.Intent; -import android.net.ConnectivityManager; import android.os.Bundle; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; import android.support.v4.view.ViewPager; import android.view.KeyEvent; -import android.widget.Button; -import android.widget.TextView; public class SampleUnderlinesNoFade extends BaseSampleActivity { private ArrayList records; - - private Button myAccountButton; - - private Button homeButton; - - private TextView headerTitle; - private SearchCatalog search; - private ArrayList searchRecords; - private Context context; - private ProgressDialog progressDialog; - private Runnable searchRunnableWithOffset; public static final int RETURN_DATA = 5; - + private Integer orgID = -1; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -75,6 +60,7 @@ public class SampleUnderlinesNoFade extends BaseSampleActivity { search = SearchCatalog.getInstance(); + orgID = getIntent().getIntExtra("orgID", -1); records = (ArrayList) getIntent().getSerializableExtra("recordList"); if (records.get(records.size() - 1).dummy == true) @@ -84,10 +70,8 @@ public class SampleUnderlinesNoFade extends BaseSampleActivity { int record_position = getIntent().getIntExtra("recordPosition", 0); mAdapter = new SearchFragmentAdapter(getSupportFragmentManager()); - mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(mAdapter); - mPager.setCurrentItem(record_position); UnderlinePageIndicator indicator = (UnderlinePageIndicator) findViewById(R.id.indicator); @@ -113,22 +97,14 @@ public class SampleUnderlinesNoFade extends BaseSampleActivity { @Override public void run() { - // don't clear record list - // recordList.clear(); if (searchRecords.size() > 0) { - for (int j = 0; j < searchRecords.size(); j++) records.add(searchRecords.get(j)); - - // add extra record to display more - // option button - } mAdapter.notifyDataSetChanged(); progressDialog.dismiss(); } }); - } }; @@ -171,15 +147,12 @@ public class SampleUnderlinesNoFade extends BaseSampleActivity { getSearchResults.start(); } return BasicDetailsFragment.newInstance(records.get(position), - position + 1, search.visible); - + position + 1, search.visible, orgID); } @Override public int getCount() { return records.size(); - // return TabsView.CONTENT.length; } - } } \ No newline at end of file diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java index 49f8975e13..9455457838 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/searchCatalog/SearchCatalog.java @@ -84,7 +84,7 @@ public class SearchCatalog { public static SearchCatalog searchCatalogSingleton = null; - public String TAG = SearchCatalog.class.getSimpleName(); + public String TAG = SearchCatalog.class.getName(); // the org on which the searches will be made public Organisation selectedOrganization = null; @@ -112,7 +112,7 @@ public class SearchCatalog { private SearchCatalog() { } - private HttpConnection conn() { + private static HttpConnection conn() { return GlobalConfigs.gatewayConnection(); } @@ -130,43 +130,36 @@ public class SearchCatalog { this.searchFormat = searchFormat; ArrayList resultsRecordInfo = new ArrayList(); - HashMap complexParm = new HashMap(); - try { - //KCXXX I'm not too sure about this depth option - if (this.selectedOrganization != null) { - if (this.selectedOrganization.id != null) - complexParm.put("org_unit", this.selectedOrganization.id); - if (this.selectedOrganization.level != null) - complexParm.put("depth", this.selectedOrganization.level); - } - complexParm.put("limit", searchLimit); - complexParm.put("offset", offset); - if (searchClass != null) complexParm.put("default_class", searchClass); -// complexParm.put("offset",0); -// complexParm.put("visibility_limit", 3000); - } catch (Exception e) { - Log.d(TAG, "Exception in JSON " + e.getMessage()); + HashMap complexParm = new HashMap(); + if (this.selectedOrganization != null) { + if (this.selectedOrganization.id != null) + complexParm.put("org_unit", this.selectedOrganization.id); + // I'm not too sure about this depth option + if (this.selectedOrganization.level != null) + complexParm.put("depth", this.selectedOrganization.level); } + complexParm.put("limit", searchLimit); + complexParm.put("offset", offset); + if (searchClass != null) complexParm.put("default_class", searchClass); String queryString = searchText; if (!searchFormat.isEmpty()) queryString += " search_format(" + searchFormat + ")"; - // do request and check for connectivity + long start_ms = System.currentTimeMillis(); + long now_ms = start_ms; + + // do request Object resp = Utils.doRequest(conn(), SERVICE, METHOD_MULTICLASS_QUERY, new Object[] { complexParm, queryString, 1 }); - - ArrayList ids = new ArrayList(); - Log.d(TAG, "Sync Response: " + resp); + now_ms = logElapsedTime(TAG, now_ms, "search"); if (resp == null) return resultsRecordInfo; // search failed or server crashed Map response = (Map) resp; - Log.d(TAG, " ids : " + response.get("ids") + " "); - List> result_ids; result_ids = (List>) response.get("ids"); Log.d(TAG, "length:"+result_ids.size()); @@ -174,6 +167,7 @@ public class SearchCatalog { // sometimes count is an int ("count":0) and sometimes string ("count":"1103") visible = Integer.parseInt(response.get("count").toString()); + ArrayList ids = new ArrayList(); for (int i = 0; i < result_ids.size(); i++) { ids.add(result_ids.get(i).get(0)); } @@ -184,15 +178,21 @@ public class SearchCatalog { Integer record_id = Integer.parseInt(ids.get(i)); RecordInfo record = new RecordInfo(getItemShortInfo(record_id)); + now_ms = logElapsedTime(TAG, now_ms, "search.getItemShortInfo"); resultsRecordInfo.add(record); AccountAccess ac = AccountAccess.getAccountAccess(); record.search_format = ac.fetchFormat(record_id.toString()); + now_ms = logElapsedTime(TAG, now_ms, "search.fetchFormat"); + // todo This takes 30% of the total search time but is not required for SearchCatalogListView + // it is needed only for BasicDetailsFragment, but that would cause it to be run on the main thread + // and that fails, so continue to do it here for now record.copyCountListInfo = getCopyCount(record_id, this.selectedOrganization.id); List> list = (List>) getLocationCount( record_id, this.selectedOrganization.id, this.selectedOrganization.level); + now_ms = logElapsedTime(TAG, now_ms, "search.getLocationCount"); if (list != null) for (int j = 0; j < list.size(); j++) { CopyInformation copyInfo = new CopyInformation(list.get(j)); @@ -204,10 +204,17 @@ public class SearchCatalog { + " Pubdate:" + record.pubdate + " Publisher:" + record.publisher); } + logElapsedTime(TAG, start_ms, "search.total"); return resultsRecordInfo; } + public long logElapsedTime(String tag, long start_ms, String s) { + long now_ms = System.currentTimeMillis(); + Log.d(tag, s + ": " + (now_ms - start_ms) + "ms"); + return now_ms; + } + /** * Gets the item short info. * @@ -256,7 +263,6 @@ public class SearchCatalog { METHOD_COPY_LOCATION_COUNTS, new Object[] { recordID, orgID, orgDepth }); return list; - } public ArrayList getRecordsInfo(ArrayList ids) { @@ -283,7 +289,7 @@ public class SearchCatalog { this.selectedOrganization = org; } - public ArrayList getCopyCount(Integer recordID, + public static ArrayList getCopyCount(Integer recordID, Integer orgID) { List list = (List) Utils.doRequestSimple(conn(), SERVICE, @@ -301,4 +307,11 @@ public class SearchCatalog { return copyInfoList; } + + // should be punted to volley + public static void ensureCopyCount(RecordInfo record, Integer org_id) { + if (record.copyCountListInfo == null) { + record.copyCountListInfo = getCopyCount(record.doc_id, org_id); + } + } } diff --git a/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java b/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java index d4b7121df9..c97d331ae9 100644 --- a/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java +++ b/Open-ILS/src/Android/core/src/org/evergreen_ils/utils/ui/BasicDetailsFragment.java @@ -61,6 +61,7 @@ public class BasicDetailsFragment extends Fragment { private final String TAG = BasicDetailsFragment.class.getName(); private RecordInfo record; + private Integer orgId; private Integer position; private Integer total; @@ -79,13 +80,10 @@ public class BasicDetailsFragment extends Fragment { private TextView copyCountTextView; private Button placeHoldButton; - private Button addToBookbagButton; private LinearLayout showMore; - private SearchCatalog search = null; - private GlobalConfigs globalConfigs; private ProgressDialog progressDialog; @@ -103,32 +101,25 @@ public class BasicDetailsFragment extends Fragment { private int list_size = 3; public static BasicDetailsFragment newInstance(RecordInfo record, - Integer position, Integer total) { + Integer position, Integer total, Integer orgID) { BasicDetailsFragment fragment = new BasicDetailsFragment(); - fragment.setDetails(record, position, total); + fragment.orgId = orgID; + fragment.record = record; + fragment.position = position; + fragment.total = total; return fragment; } - private void setDetails(RecordInfo record, Integer position, - Integer total) { - - this.record = record; - this.position = position; - this.total = total; - } - public BasicDetailsFragment() { - - search = SearchCatalog.getInstance(); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { - record = (RecordInfo) savedInstanceState - .getSerializable("recordInfo"); + record = (RecordInfo) savedInstanceState.getSerializable("recordInfo"); + orgId = savedInstanceState.getInt("orgId"); this.position = savedInstanceState.getInt("position"); this.total = savedInstanceState.getInt("total"); } @@ -165,8 +156,7 @@ public class BasicDetailsFragment extends Fragment { @Override public void onClick(View v) { - Intent intent = new Intent(getActivity() - .getApplicationContext(), PlaceHold.class); + Intent intent = new Intent(getActivity().getApplicationContext(), PlaceHold.class); intent.putExtra("recordInfo", record); startActivity(intent); } @@ -275,17 +265,15 @@ public class BasicDetailsFragment extends Fragment { isbnTextView.setText(record.isbn); - int current_org = 0; - if (search != null) - current_org = search.selectedOrganization.id; + // todo this is not working because we are on the main thread + //SearchCatalog.ensureCopyCount(record, orgId); Log.d(TAG, "Size " + record.copyCountListInfo.size()); - for (int i = 0; i < record.copyCountListInfo.size(); i++) { - Log.d(TAG, current_org + " " - + record.copyCountListInfo.get(i).org_id + " " - + record.copyCountListInfo.get(i).count); - if (record.copyCountListInfo.get(i).org_id == current_org) { +// Log.d(TAG, orgId + " " +// + record.copyCountListInfo.get(i).org_id + " " +// + record.copyCountListInfo.get(i).count); + if (record.copyCountListInfo.get(i).org_id == orgId) { int total = record.copyCountListInfo.get(i).count; int available = record.copyCountListInfo.get(i).available; String totalCopies = getResources().getQuantityString(R.plurals.number_of_copies, total, total); @@ -303,9 +291,9 @@ public class BasicDetailsFragment extends Fragment { @Override public void onClick(View v) { // show more details - Intent intent = new Intent(getActivity() - .getApplicationContext(), MoreCopyInformation.class); + Intent intent = new Intent(getActivity().getApplicationContext(), MoreCopyInformation.class); intent.putExtra("recordInfo", record); + intent.putExtra("orgId", orgId); startActivity(intent); } }); @@ -324,6 +312,7 @@ public class BasicDetailsFragment extends Fragment { @Override public void onSaveInstanceState(Bundle outState) { outState.putSerializable("recordInfo", record); + outState.putInt("orgId", this.orgId); outState.putInt("position", this.position); outState.putInt("total", this.total); super.onSaveInstanceState(outState); diff --git a/Open-ILS/src/Android/kenstir_parse_logcat.pl b/Open-ILS/src/Android/kenstir_parse_logcat.pl index ccb30efb96..4add95796b 100644 --- a/Open-ILS/src/Android/kenstir_parse_logcat.pl +++ b/Open-ILS/src/Android/kenstir_parse_logcat.pl @@ -20,7 +20,11 @@ foreach my $line (@lines) { if ($line =~ /GatewayRequest: ([^:]+):(.+)/) { my($key,$val) = ($1,$2); if ($key eq 'result') { - my $obj = decode_json($val); + my $obj; + eval '$obj = decode_json($val);'; + if ($@) { + $obj = '*** '.$val; + } print "$key -> ", Dumper($obj); } else { print "${key}:${val}\n"; diff --git a/Open-ILS/src/Android/opensrf/src/org/opensrf/net/http/GatewayRequest.java b/Open-ILS/src/Android/opensrf/src/org/opensrf/net/http/GatewayRequest.java index 64d861fa5b..be864328aa 100644 --- a/Open-ILS/src/Android/opensrf/src/org/opensrf/net/http/GatewayRequest.java +++ b/Open-ILS/src/Android/opensrf/src/org/opensrf/net/http/GatewayRequest.java @@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; public class GatewayRequest extends HttpRequest { private boolean readComplete; - private String TAG = GatewayRequest.class.getSimpleName(); + private String TAG = GatewayRequest.class.getName(); public GatewayRequest(HttpConnection conn, String service, Method method) { super(conn, service, method);