User Tools

Site Tools


scratchpad:random_magic_spells

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

scratchpad:random_magic_spells [2015/08/19 15:31] – [Checking Circ/Hold Flags on an Item] phasefxscratchpad:random_magic_spells [2022/02/10 13:34] (current) – external edit 127.0.0.1
Line 228: Line 228:
 netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); JSAN.use('util.file'); var f = new util.file('ws_info'); alert(f._file.path); netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); JSAN.use('util.file'); var f = new util.file('ws_info'); alert(f._file.path);
 </code> </code>
 +
 +====== Performance ======
 +=====Preload Your database into RAM=====
 +Find your database's oid and make a note of it:
 +<code>
 +psql -U evergreen -h localhost -d postgres -c "select oid from pg_database where datname = 'evergreen'"
 +</code>
 +
 +Then, as the root or postgres user, run the following commands
 +<code>
 +cd /var/lib/postgresql/${pgversion}/main/base/${oid}
 +cat * > /dev/null
 +</code>
 +
 +Replace ${pgversion} with your PostgreSQL version number, ex. 9.5.  Replace ${oid} with the number returned by the database query.
  
 ====== Utility ====== ====== Utility ======
Line 462: Line 477:
 </code> </code>
  
 +===== Generating a SQL report with natural titles =====
 +
 +While the reporter.materialized_simple_record view is convenient, sometimes those all-lowercase titles are annoying (for example, in shelf list reports that you're preparing for public consumption). In those cases, a little XPATH can go a long way--but you need to correct for the XML array that XPATH() returns, which you can do with ARRAY_TO_STRING() like the following:
 +
 +<code sql>
 +SELECT 
 +  ARRAY_TO_STRING(
 +    XPATH('//marc:datafield[@tag="245"][1]//text()',
 +      marc::XML, ARRAY[ARRAY['marc', 'http://www.loc.gov/MARC21/slim']]
 +    ),
 +    ' '
 +  )
 +FROM biblio.record_entry WHERE ...
 +</code>
 ====== Statistics ====== ====== Statistics ======
  
Line 525: Line 554:
 ; ;
 </code> </code>
 +
 +
 +=====Show statistic usage on reports===
 +
 +<code sql>
 +select thecount.name,create_time,thecount.lasttime,thecount.count from
 +reporter.template rt,
 +(
 +select rtinner.name "name",max(run_time) "lasttime",count(*) "count" from reporter.schedule rs,reporter.report rr,
 +(select naming.name,string_agg(clones.id||'',',') ids from
 +reporter.template naming ,
 +reporter.template clones
 +where
 +clones.data=naming.data and
 +naming.folder in(select id from reporter.template_folder where owner= !!!REPLACE ME WITH OWNER ID!!! and shared and share_with=1) and
 +naming.owner=  !!!REPLACE ME WITH OWNER ID!!!
 +group by 1
 +) rtinner
 +
 +where rr.template = any(('{'||rtinner.ids||'}')::int[]) and rr.id=rs.report
 +group by 1
 +
 +) as thecount
 +where
 +thecount.name = rt.name and
 +rt.owner=  !!!REPLACE ME WITH OWNER ID!!!  and
 +rt.folder in(select id from reporter.template_folder where owner= !!!REPLACE ME WITH OWNER ID!!! and shared and share_with=1)
 +order by 4 desc
 +
 +</code>
 +
 +You will need to edit that query to look for reports owned by a particular actor.usr.id. Replace "!!!REPLACE ME WITH OWNER ID!!!" with the ID number. This is useful when you have centralized report templates for everyone to use. It also takes into account cloned reports from the same source template!
  
 ====== Development ====== ====== Development ======
Line 648: Line 709:
 </code> </code>
  
 +=====Getting a hierarchically-ordered list of org units=====
 +<code sql>
 +-- breadth-first (i.e. all first-level org units, then all second-level OUs, etc.)
 +WITH RECURSIVE orgs AS
 +(
 +  SELECT id, shortname, name, parent_ou
 +  FROM actor.org_unit
 +  WHERE parent_ou IS NULL
 +  UNION ALL
 +  SELECT next.id, next.shortname, next.name, next.parent_ou 
 +  FROM actor.org_unit next
 +  JOIN orgs prev ON next.parent_ou = prev.id
 +)
 +SELECT id, shortname, name, parent_ou
 +FROM orgs;
 +
 +-- depth-first ("expanded tree" order, as in most org selector dropdown menus)
 +WITH RECURSIVE orgs AS
 +(
 +  SELECT id, shortname, name, parent_ou, array[id] AS path
 +  FROM actor.org_unit
 +  WHERE parent_ou IS NULL
 +  UNION
 +  SELECT next.id, next.shortname, next.name, next.parent_ou, (prev.path || next.id) AS path
 +  FROM actor.org_unit next
 +  JOIN orgs prev ON next.parent_ou = prev.id
 +)
 +SELECT id, shortname, name, parent_ou
 +FROM orgs ORDER BY path;
 +</code>
 ====== Cstore/json_query tips and tricks ====== ====== Cstore/json_query tips and tricks ======
  
Line 701: Line 792:
 like the type of file you get when you use Export from the Receipt Template like the type of file you get when you use Export from the Receipt Template
 Editor.  You could trim the contents to override only specific templates. Editor.  You could trim the contents to override only specific templates.
 +
 +**Alternate version with per workstation OU settings**
 +If you would like to manage print templates centrally with the ability to have different settings
 +per Org Unit, this variant allows you to have default print_list_template and then a version for specific Org units, print_list_template-oushortname.
 +
 +<code javascript>
 +//////////////////////////////////////////////////////////////////////////
 +// Overriding receipt templates globally
 +
 +try {
 +    // In practice, this should be true in menu.js/opac.js, but not util_overlay.xul
 +    if (typeof JSAN != 'undefined' && typeof JSON2js != 'undefined' && typeof xulG != 'undefined') {
 +        var r = new XMLHttpRequest();
 +        //request the OU specific print_list_templates files
 +        r.open("GET", xulG.url_prefix('/xul/server/skin/print_list_templates') + '-' + ses('ws_ou_shortname'), false);
 +        r.send(null);
 +        if (r.status != 200) {
 +           //request the default print_list_templates file.
 +           r.open("GET", xulG.url_prefix('/xul/server/skin/print_list_templates'), false);
 +           r.send(null);
 +        }
 +        if (r.status == 200) {
 +            JSAN.use('OpenILS.data');
 +            var custom_data = new OpenILS.data(); custom_data.stash_retrieve();
 +            var custom_templates = JSON2js( r.responseText );
 +            for (var i in custom_templates) {
 +                custom_data.print_list_templates[i] = custom_templates[i];
 +            }
 +            custom_data.stash('print_list_templates');
 +            dump('Overriding receipt templates via custom.js\n');
 +        }
 +    }
 +} catch(E) {
 +    dump('Error overriding receipt templates in custom.js: ' + E + '\n');
 +}
 +</code>
 +
 +First /openils/var/web/xul/server/skin/print_list_templates-OUSHORTNAME is checked, then
 + /openils/var/web/xul/server/skin/print_list_templates is checked if the OU specific version doesn't
 +exist.  Both files should be a file just
 +like the type of file you get when you use Export from the Receipt Template
 +Editor.  You could trim the contents to override only specific templates.
 +
 +===== Clear the added content cache (book covers, etc) from the command line =====
 +
 +While newer versions of Evergreen offer the ability to [[http://docs.evergreen-ils.org/2.9/_including_external_content_in_your_public_interface.html#_clear_external_added_content_cache|clear the cache for a given record through the staff client]], sometimes doing it from the command line is a better option.
 +
 +If you want to clear the cache for a given record by its database ID, you can do the following from the command line (substitute 12345678 for the record ID, and modify your memcached server address if necessary):
 +
 +<code bash>
 +export MEMCACHED_SERVERS=127.0.0.1; memcdump | grep ^ac\\..*record_12345678 | xargs memcrm
 +</code>
 +
 +Thank you Jeff Godin for this tip!
 +
 +===== Clear cached catalog search results =====
 +
 +Similar to the spell above, this can be used to clear all cached catalog search results and facets from memcached. This ordinarily isn't needed for production use, but can be useful when testing tweaks to search code or settings.
 +
 +<code bash>
 +memcdump --servers localhost|grep open-ils.search | xargs -n 1 memcrm --servers localhost
 +</code>
scratchpad/random_magic_spells.1440012680.txt.gz · Last modified: 2022/02/10 13:33 (external edit)

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.