Skip to content

Commit f318366

Browse files
rubenwardyparamat
authored andcommitted
Fix ContentDB packages timing out by using download_file instead (#7891)
1 parent a833bee commit f318366

File tree

4 files changed

+31
-81
lines changed

4 files changed

+31
-81
lines changed

builtin/mainmenu/dlg_contentstore.lua

+31-3
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,37 @@ function package_dialog.create(package)
268268
end
269269

270270
function store.load()
271-
store.packages_full = core.get_package_list()
272-
store.packages = store.packages_full
273-
store.loaded = true
271+
local tmpdir = os.tempfolder()
272+
local target = tmpdir .. DIR_DELIM .. "packages.json"
273+
274+
assert(core.create_dir(tmpdir))
275+
276+
local base_url = core.settings:get("contentdb_url")
277+
local show_nonfree = core.settings:get_bool("show_nonfree_packages")
278+
local url = base_url ..
279+
"/api/packages/?type=mod&type=game&type=txp&protocol_version=" ..
280+
core.get_max_supp_proto() ..
281+
"&nonfree=" ..
282+
(show_nonfree and "true" or "false")
283+
284+
core.download_file(url, target)
285+
286+
local file = io.open(target, "r")
287+
if file then
288+
store.packages_full = core.parse_json(file:read("*all"))
289+
file:close()
290+
291+
for _, package in pairs(store.packages_full) do
292+
package.url = base_url .. "/packages/" ..
293+
package.author .. "/" .. package.name ..
294+
"/releases/" .. package.release .. "/download/"
295+
end
296+
297+
store.packages = store.packages_full
298+
store.loaded = true
299+
end
300+
301+
core.delete_dir(tmpdir)
274302
end
275303

276304
function store.update_paths()

doc/menu_lua_api.txt

-11
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,6 @@ Package - content which is downloadable from the content db, may or may not be i
146146
optional_depends = {"mod", "names"}, -- mods only
147147
}
148148

149-
* core.get_package_list() -> downloads package list from content db
150-
* returns a list of:
151-
152-
{
153-
name = "basename",
154-
title = "human readable title",
155-
author = "username",
156-
type = "", -- mod, game, txp
157-
short_description = "description",
158-
url = "",
159-
}
160149

161150
Favorites:
162151
core.get_favorites(location) -> list of favorites (possible in async calls)

src/script/lua_api/l_mainmenu.cpp

-64
Original file line numberDiff line numberDiff line change
@@ -991,68 +991,6 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L)
991991
return 1;
992992
}
993993

994-
int ModApiMainMenu::l_get_package_list(lua_State *L)
995-
{
996-
std::string url = g_settings->get("contentdb_url");
997-
bool show_nonfree = g_settings->getBool("show_nonfree_packages");
998-
std::vector<Package> packages = getPackagesFromURL(url +
999-
"/api/packages/?type=mod&type=game&type=txp&protocol_version="
1000-
LATEST_PROTOCOL_VERSION_STRING "&nonfree=" +
1001-
(show_nonfree ? "true" : "false"));
1002-
1003-
// Make table
1004-
lua_newtable(L);
1005-
int top = lua_gettop(L);
1006-
unsigned int index = 1;
1007-
1008-
// Fill table
1009-
for (const auto &package : packages) {
1010-
lua_pushnumber(L, index);
1011-
lua_newtable(L);
1012-
1013-
int top_lvl2 = lua_gettop(L);
1014-
1015-
lua_pushstring(L, "author");
1016-
lua_pushstring(L, package.author.c_str());
1017-
lua_settable (L, top_lvl2);
1018-
1019-
lua_pushstring(L, "name");
1020-
lua_pushstring(L, package.name.c_str());
1021-
lua_settable (L, top_lvl2);
1022-
1023-
lua_pushstring(L, "title");
1024-
lua_pushstring(L, package.title.c_str());
1025-
lua_settable (L, top_lvl2);
1026-
1027-
lua_pushstring(L, "type");
1028-
lua_pushstring(L, package.type.c_str());
1029-
lua_settable (L, top_lvl2);
1030-
1031-
lua_pushstring(L, "short_description");
1032-
lua_pushstring(L, package.shortDesc.c_str());
1033-
lua_settable (L, top_lvl2);
1034-
1035-
lua_pushstring (L, "release");
1036-
lua_pushinteger(L, package.release);
1037-
lua_settable (L, top_lvl2);
1038-
1039-
if (package.thumbnail != "") {
1040-
lua_pushstring(L, "thumbnail");
1041-
lua_pushstring(L, package.thumbnail.c_str());
1042-
lua_settable (L, top_lvl2);
1043-
}
1044-
1045-
lua_pushstring(L, "url");
1046-
lua_pushstring(L, package.getDownloadURL(url).c_str());
1047-
lua_settable (L, top_lvl2);
1048-
1049-
lua_settable(L, top);
1050-
index++;
1051-
}
1052-
1053-
return 1;
1054-
}
1055-
1056994
/******************************************************************************/
1057995
int ModApiMainMenu::l_get_min_supp_proto(lua_State *L)
1058996
{
@@ -1123,7 +1061,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
11231061
API_FCT(get_video_drivers);
11241062
API_FCT(get_video_modes);
11251063
API_FCT(get_screen_info);
1126-
API_FCT(get_package_list);
11271064
API_FCT(get_min_supp_proto);
11281065
API_FCT(get_max_supp_proto);
11291066
API_FCT(do_async_callback);
@@ -1147,5 +1084,4 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
11471084
//API_FCT(extract_zip); //TODO remove dependency to GuiEngine
11481085
API_FCT(download_file);
11491086
//API_FCT(gettext); (gettext lib isn't threadsafe)
1150-
API_FCT(get_package_list);
11511087
}

src/script/lua_api/l_mainmenu.h

-3
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,6 @@ class ModApiMainMenu: public ModApiBase
133133

134134
static int l_get_video_modes(lua_State *L);
135135

136-
//content store
137-
static int l_get_package_list(lua_State *L);
138-
139136
//version compatibility
140137
static int l_get_min_supp_proto(lua_State *L);
141138

0 commit comments

Comments
 (0)