1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-10-27 20:34:16 +00:00

Scribunto: Cache results of title.exists [#597]

This commit is contained in:
gnosygnu 2019-11-18 06:25:57 -05:00
parent 41a521850b
commit b2864f8c6a
3 changed files with 17 additions and 9 deletions

View File

@ -31,9 +31,11 @@ public class Xow_page_cache_itm implements Xowd_text_bry_owner {
public boolean Cache_permanently() {return cache_permanently;} private final boolean cache_permanently;
public long Cache_len() {return cache_len;}
// used by xomp
public int Page_id() {return page_id;} private int page_id;
public int Redirect_id() {return redirect_id;} private int redirect_id;
// used by xomp; Scrib_ttl
public int Page_id() {return page_id;} private int page_id = -1;
public boolean Page_exists() {return page_id != -1;}
public int Redirect_id() {return redirect_id;} private int redirect_id = -1;
public boolean Redirect_exists() {return redirect_id != -1;}
public void Set_text_bry_by_db(byte[] v) {
this.wtxt__direct = v;
this.cache_len = wtxt__direct == null ? 0 : wtxt__direct.length;

View File

@ -147,11 +147,11 @@ public class Scrib_lib_title implements Scrib_lib {
if (ttl == Xoa_ttl.Null) return rslt.Init_null();
// TODO_OLD: MW does extra logic here to cache ttl in ttl cache to avoid extra title lookups
boolean ttl_exists = false, ttl_redirect = false; int ttl_id = 0;
Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
ttl_exists = core.Wiki().Db_mgr().Load_mgr().Load_by_ttl(db_page, ttl.Ns(), ttl.Page_db());
if (ttl_exists) {
ttl_redirect = db_page.Redirected();
ttl_id = db_page.Id();
Xow_page_cache_itm cache_itm = core.Wiki().Cache_mgr().Page_cache().Get_itm_else_load_or_null(ttl);
if (cache_itm != null) {
ttl_exists = cache_itm.Page_exists();
ttl_id = cache_itm.Page_id();
ttl_redirect = cache_itm.Redirect_exists();
}
Keyval[] rv = new Keyval[4];
rv[ 0] = Keyval_.new_("isRedirect" , ttl_redirect); // title.isRedirect

View File

@ -14,7 +14,7 @@ GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.xtns.scribunto.libs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
import org.junit.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
import org.junit.*; import gplx.core.tests.*; import gplx.xowa.xtns.scribunto.engines.mocks.*;
public class Scrib_lib_title_tst {
private final Mock_scrib_fxt fxt = new Mock_scrib_fxt(); private Scrib_lib lib;
@Before public void init() {
@ -77,6 +77,12 @@ public class Scrib_lib_title_tst {
fxt.Parser_fxt().Init_page_create("A");
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_getExpensiveData, Object_.Ary("A") , ttl_slow(Bool_.Y, 0, Bool_.N));
}
@Test public void GetExpensiveData_cache() { // ISSUE#:597; DATE:2019-11-18
gplx.xowa.wikis.caches.Xow_page_cache cache_mgr = fxt.Parser_fxt().Wiki().Cache_mgr().Page_cache();
Gftest.Eq__bool(Bool_.N, cache_mgr.Get_itm_or_null("A") != null); // item does not exist
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_getExpensiveData, Object_.Ary("A") , ttl_slow(Bool_.N, 0, Bool_.N));
Gftest.Eq__bool(Bool_.Y, cache_mgr.Get_itm_or_null("A") != null); // item exists
}
@Test public void GetFileInfo() {
Wiki_orig_tbl__create(fxt.Core().Wiki());
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_getFileInfo, Object_.Ary("A") , file_info_absent());