mirror of
https://github.com/gnosygnu/xowa.git
synced 2025-05-31 22:44:34 +00:00
Mass_parse: Add separate ifexists cache
This commit is contained in:
parent
38f5f6de7c
commit
2f3a3a7a16
@ -20,6 +20,7 @@ public class Xow_page_cache {
|
||||
private final Object thread_lock = new Object();
|
||||
private final Xowe_wiki wiki;
|
||||
private final Ordered_hash cache = Ordered_hash_.New_bry(); // NOTE: wiki titles are not case-sensitive when ns is "1st-letter" (EX: w:earth an w:Earth); in these cases, two entries will be stored
|
||||
private final Hash_adp ifexists_cache = Hash_adp_bry.cs();
|
||||
private final List_adp deleted = List_adp_.New();
|
||||
private Xow_page_cache_wkr load_wkr;
|
||||
public Xow_page_cache(Xowe_wiki wiki) {this.wiki = wiki;}
|
||||
@ -29,6 +30,45 @@ public class Xow_page_cache {
|
||||
Xow_page_cache_itm rv = Get_or_load_as_itm(ttl);
|
||||
return rv == null ? null : rv.Wtxt__direct();
|
||||
}
|
||||
public boolean Get_ifexist_by_mem(byte[] ifexists_key) {
|
||||
Xow_page_cache_itm ifexists_itm = (Xow_page_cache_itm)ifexists_cache.Get_by(ifexists_key);
|
||||
if (ifexists_itm == Xow_page_cache_itm.Missing)
|
||||
return false;
|
||||
else if (ifexists_itm != null)
|
||||
return true;
|
||||
|
||||
// check page_cache
|
||||
ifexists_itm = (Xow_page_cache_itm)cache.Get_by(ifexists_key);
|
||||
if (ifexists_itm == Xow_page_cache_itm.Missing)
|
||||
return false;
|
||||
else if (ifexists_itm != null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
public boolean Load_ifexist(Xoa_ttl ttl) {
|
||||
// check ifexists_cache
|
||||
byte[] ifexists_key = ttl.Full_db();
|
||||
Xow_page_cache_itm ifexists_itm = null;
|
||||
|
||||
// do load
|
||||
if (load_wkr != null) {
|
||||
// load_wkr
|
||||
byte[] page_text = load_wkr.Get_page_or_null(ifexists_key);
|
||||
ifexists_itm = page_text == null ? Xow_page_cache_itm.Missing : new Xow_page_cache_itm(false, ttl, Bry_.Empty, Bry_.Empty);
|
||||
}
|
||||
else {
|
||||
// page_tbl
|
||||
gplx.xowa.wikis.data.tbls.Xowd_page_itm page_itm = new gplx.xowa.wikis.data.tbls.Xowd_page_itm();
|
||||
wiki.Db_mgr().Load_mgr().Load_by_ttl(page_itm, ttl.Ns(), ttl.Page_db());
|
||||
// wiki.Data__core_mgr().Db__core().Tbl__page().Select_by_ttl(page_itm, ttl);
|
||||
ifexists_itm = page_itm.Exists() ? new Xow_page_cache_itm(false, ttl, Bry_.Empty, Bry_.Empty) : Xow_page_cache_itm.Missing;
|
||||
}
|
||||
|
||||
// add to ifexists_cache only (not page_cache)
|
||||
ifexists_cache.Add(ifexists_key, ifexists_itm);
|
||||
return ifexists_itm != Xow_page_cache_itm.Missing;
|
||||
}
|
||||
public void Add(byte[] ttl_full_db, Xow_page_cache_itm itm) {
|
||||
cache.Add(ttl_full_db, itm);
|
||||
}
|
||||
@ -97,8 +137,10 @@ public class Xow_page_cache {
|
||||
}
|
||||
public void Free_mem(boolean clear_permanent_itms) {
|
||||
synchronized (thread_lock) { // LOCK:app-level; DATE:2016-07-06
|
||||
if (clear_permanent_itms)
|
||||
if (clear_permanent_itms) {
|
||||
cache.Clear();
|
||||
ifexists_cache.Clear();
|
||||
}
|
||||
else {
|
||||
int len = cache.Count();
|
||||
for (int i = 0; i < len; i++) {
|
||||
|
@ -27,38 +27,31 @@ public class Pfunc_ifexist_mgr {
|
||||
byte[] ttl_bry = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
|
||||
|
||||
// try to get from cache
|
||||
Gfo_cache_mgr cache_mgr = wiki.Cache_mgr().Ifexist_cache();
|
||||
Pfunc_ifexist_itm cache_itm = (Pfunc_ifexist_itm)cache_mgr.Get_by_key(ttl_bry);
|
||||
if (cache_itm != null) return cache_itm.Exists();
|
||||
|
||||
cache_itm = new Pfunc_ifexist_itm(ttl_bry);
|
||||
cache_mgr.Add(ttl_bry, cache_itm, 1);
|
||||
if (wiki.Cache_mgr().Page_cache().Get_ifexist_by_mem(ttl_bry)) return true;
|
||||
db_page.Clear();
|
||||
Xow_ns ttl_ns = ttl.Ns();
|
||||
boolean rv = false;
|
||||
switch (ttl_ns.Id()) {
|
||||
case Xow_ns_.Tid__special: rv = true; break; // NOTE: some pages call for [[Special]]; always return true for now; DATE:2014-07-17
|
||||
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(cache_itm, wiki, ttl_ns, ttl_bry); break;
|
||||
default: rv = Find_ttl_in_db(cache_itm, wiki, ttl, ttl_ns, ttl_bry); break;
|
||||
case Xow_ns_.Tid__media: rv = Find_ttl_for_media_ns(wiki, ttl_ns, ttl_bry); break;
|
||||
default: rv = Find_ttl_in_db(wiki, ttl, ttl_ns, ttl_bry); break;
|
||||
}
|
||||
cache_itm.Exists_(rv);
|
||||
return rv;
|
||||
}
|
||||
private boolean Find_ttl_in_db(Pfunc_ifexist_itm itm, Xowe_wiki wiki, Xoa_ttl ttl, Xow_ns ns, byte[] ttl_bry) {
|
||||
boolean rv = wiki.Cache_mgr().Page_cache().Get_or_load_as_src(ttl) != null;
|
||||
private boolean Find_ttl_in_db(Xowe_wiki wiki, Xoa_ttl ttl, Xow_ns ns, byte[] ttl_bry) {
|
||||
boolean rv = wiki.Cache_mgr().Page_cache().Load_ifexist(ttl);
|
||||
if ( !rv
|
||||
&& wiki.Lang().Vnt_mgr().Enabled()) {
|
||||
Xowd_page_itm page = wiki.Lang().Vnt_mgr().Convert_mgr().Convert_ttl(wiki, ns, ttl_bry);
|
||||
if (page != Xowd_page_itm.Null)
|
||||
rv = page.Exists();
|
||||
}
|
||||
itm.Exists_(rv);
|
||||
return rv;
|
||||
}
|
||||
private boolean Find_ttl_for_media_ns(Pfunc_ifexist_itm itm, Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
|
||||
private boolean Find_ttl_for_media_ns(Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
|
||||
Xow_ns file_ns = wiki.Ns_mgr().Ns_file();
|
||||
Xoa_ttl file_ttl = wiki.Ttl_parse(file_ns.Id(), ttl_bry);
|
||||
boolean rv = Find_ttl_in_db(itm, wiki, file_ttl, file_ns, ttl_bry); if (rv) return true; // rarely true, but check local wiki's [[File:]] table anyway
|
||||
boolean rv = Find_ttl_in_db(wiki, file_ttl, file_ns, ttl_bry); if (rv) return true; // rarely true, but check local wiki's [[File:]] table anyway
|
||||
Xowe_wiki commons_wiki = wiki.Appe().Wiki_mgr().Wiki_commons();
|
||||
boolean env_is_testing = Env_.Mode_testing();
|
||||
if ( commons_wiki != null // null check
|
||||
@ -67,7 +60,7 @@ public class Pfunc_ifexist_mgr {
|
||||
)
|
||||
) {
|
||||
file_ns = commons_wiki.Ns_mgr().Ns_file();
|
||||
return Find_ttl_in_db(itm, commons_wiki, file_ttl, file_ns, ttl_bry); // accurate test using page table in commons wiki (provided commons is up to date)
|
||||
return Find_ttl_in_db(commons_wiki, file_ttl, file_ns, ttl_bry); // accurate test using page table in commons wiki (provided commons is up to date)
|
||||
}
|
||||
else {
|
||||
if (!env_is_testing)
|
||||
|
Loading…
Reference in New Issue
Block a user