1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Mass_parse: Refactor ifexist_mgr into separate class; Load more titles into ifexist_mgr

This commit is contained in:
gnosygnu
2016-12-16 13:23:48 -05:00
parent bfc5c5b68e
commit 5b42a90cd5
8 changed files with 207 additions and 102 deletions

View File

@@ -20,26 +20,29 @@ import gplx.core.envs.*; import gplx.core.caches.*;
import gplx.xowa.apps.wms.apis.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.wikis.nss.*;
public class Pfunc_ifexist_mgr {
private final Xowd_page_itm db_page = Xowd_page_itm.new_tmp();
public boolean Exists(Xowe_wiki wiki, byte[] raw_bry) {
if (Bry_.Len_eq_0(raw_bry)) return false; // return early; NOTE: {{autolink}} can pass in "" (see test)
Xoa_ttl ttl = Xoa_ttl.Parse(wiki, raw_bry); if (ttl == null) return false;
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
if (wiki.Cache_mgr().Page_cache().Get_ifexist_by_mem(ttl_bry)) return true;
db_page.Clear();
Xow_ns ttl_ns = ttl.Ns();
byte exists = wiki.Cache_mgr().Ifexist_cache().Get_by_mem(ttl);
if (exists == Bool_.Y_byte) return true;
else if (exists == Bool_.N_byte) return false;
byte[] page_db = ttl.Page_db(); // NOTE: must use Page_db; EX: {{#ifexist:File:Peter & Paul fortress in SPB 03.jpg|y|n}}
Xow_ns ns = ttl.Ns();
boolean rv = false;
switch (ttl_ns.Id()) {
switch (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(wiki, ttl_ns, ttl_bry); break;
default: rv = Find_ttl_in_db(wiki, ttl, ttl_ns, ttl_bry); break;
case Xow_ns_.Tid__media: rv = Find_by_ns__media(wiki, ns, page_db); break;
default: rv = Find_by_ns(wiki, ttl, ns, page_db); break;
}
return rv;
}
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);
private boolean Find_by_ns(Xowe_wiki wiki, Xoa_ttl ttl, Xow_ns ns, byte[] ttl_bry) {
boolean rv = wiki.Cache_mgr().Ifexist_cache().Load(ttl);
// handle variants
if ( !rv
&& wiki.Lang().Vnt_mgr().Enabled()) {
Xowd_page_itm page = wiki.Lang().Vnt_mgr().Convert_mgr().Convert_ttl(wiki, ns, ttl_bry);
@@ -48,10 +51,18 @@ public class Pfunc_ifexist_mgr {
}
return rv;
}
private boolean Find_ttl_for_media_ns(Xowe_wiki wiki, Xow_ns ns, byte[] ttl_bry) {
private boolean Find_by_ns__media(Xowe_wiki wiki, Xow_ns ns, byte[] page_db) {
// rarely true, but check local wiki's [[File:]] table anyway
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(wiki, file_ttl, file_ns, ttl_bry); if (rv) return true; // rarely true, but check local wiki's [[File:]] table anyway
Xoa_ttl file_ttl = wiki.Ttl_parse(file_ns.Id(), page_db);
byte exists = wiki.Cache_mgr().Ifexist_cache().Get_by_mem(file_ttl);
if (exists == Bool_.Y_byte) return true;
else if (exists == Bool_.N_byte) return false;
if (Find_by_ns(wiki, file_ttl, file_ns, page_db)) return true;
// check commons; either (a) commons_wiki directly; or (b) tdb's file_mgr; note that (b) is obsolete
Xowe_wiki commons_wiki = wiki.Appe().Wiki_mgr().Wiki_commons();
boolean env_is_testing = Env_.Mode_testing();
if ( commons_wiki != null // null check
@@ -60,18 +71,12 @@ public class Pfunc_ifexist_mgr {
)
) {
file_ns = commons_wiki.Ns_mgr().Ns_file();
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)
return Find_by_ns(commons_wiki, file_ttl, file_ns, page_db); // accurate test using page table in commons wiki (provided commons is up to date)
}
else {
if (!env_is_testing)
wiki.File_mgr().Init_file_mgr_by_load(wiki); // NOTE: must init Fsdb_mgr (else conn == null), and with bin_wkrs (else no images will ever load); DATE:2014-09-21
return wiki.File_mgr().Exists(ttl_bry); // less-accurate test using either (1) orig_wiki table in local wiki (v2) or (2) meta_db_mgr (v1)
return wiki.File_mgr().Exists(page_db); // less-accurate test using either (1) orig_wiki table in local wiki (v2) or (2) meta_db_mgr (v1)
}
}
}
class Pfunc_ifexist_itm implements Rls_able {
public Pfunc_ifexist_itm(byte[] ttl) {this.ttl = ttl;}
public byte[] Ttl() {return ttl;} private byte[] ttl;
public boolean Exists() {return exists;} public void Exists_(boolean v) {exists = v;} private boolean exists;
public void Rls() {}
}
}