commit ed21a9a1021f38c009ef8a0ea6049587e3b4373b from: Omar Polo date: Tue Jan 11 13:44:10 2022 UTC provide a way to bypass the cache This changes the last argument of load_url to be a `mode' bitmap instead of a boolean ``nohist''. LU_MODE_NOHIST is the old 1, LU_MODE_NONE is provided just for readability and the new LU_MODE_NOCACHE allows to bypass the caching when loading a page. Telescope only uses the cache when: - re-opens a closed tab - navigates backward and forward in the history All other situations result in the usual network request. commit - dc8e7bf65a6ca6deb0e7dec7ebcf22286604c321 commit + ed21a9a1021f38c009ef8a0ea6049587e3b4373b blob - e7100358e688c1795ce9e52a2ec0aafd1d6c4e4f blob + 8a1d6d723da36ee7816a2f9dcc0644c5ba32f5f1 --- cmd.c +++ cmd.c @@ -300,7 +300,8 @@ cmd_push_button(struct buffer *buffer) switch (vl->parent->type) { case LINE_LINK: - load_url_in_tab(current_tab, vl->parent->alt, NULL, 0); + load_url_in_tab(current_tab, vl->parent->alt, NULL, + LU_MODE_NOCACHE); break; case LINE_PRE_START: l = TAILQ_NEXT(vl->parent, lines); @@ -585,7 +586,8 @@ cmd_load_current_url(struct buffer *buffer) void cmd_reload_page(struct buffer *buffer) { - load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL, 1); + load_url_in_tab(current_tab, current_tab->hist_cur->h, NULL, + LU_MODE_NOHIST|LU_MODE_NOCACHE); } void @@ -603,7 +605,7 @@ cmd_bookmark_page(struct buffer *buffer) void cmd_list_bookmarks(struct buffer *buffer) { - load_url_in_tab(current_tab, "about:bookmarks", NULL, 0); + load_url_in_tab(current_tab, "about:bookmarks", NULL, LU_MODE_NONE); } void blob - 1d8c0e73982110f78bbfa3da22ae02878591f112 blob + be653281850cd821fbd43660366ff8e775f8745c --- minibuffer.c +++ minibuffer.c @@ -231,7 +231,7 @@ ir_select_gemini(void) memcpy(&uri, &tab->uri, sizeof(tab->uri)); phos_uri_set_query(&uri, ministate.buf); phos_serialize_uri(&uri, buf, sizeof(buf)); - load_url_in_tab(tab, buf, NULL, 0); + load_url_in_tab(tab, buf, NULL, LU_MODE_NOCACHE); } void @@ -252,7 +252,7 @@ lu_select(void) minibuffer_hist_save_entry(); humanify_url(ministate.buf, url, sizeof(url)); - load_url_in_tab(current_tab, url, NULL, 0); + load_url_in_tab(current_tab, url, NULL, LU_MODE_NOCACHE); } void @@ -290,7 +290,7 @@ ls_select(void) } exit_minibuffer(); - load_url_in_tab(current_tab, l->alt, NULL, 0); + load_url_in_tab(current_tab, l->alt, NULL, LU_MODE_NOCACHE); } static inline void blob - bdf7e8b6ce3ff81541ab1fae0ee2f6d0afabea25 blob + b59e584b3f0378b4453a75bfbadb04f4904b2d57 --- session.c +++ session.c @@ -39,7 +39,7 @@ switch_to_tab(struct tab *tab) if (operating && tab->flags & TAB_LAZY) { tab->flags ^= TAB_LAZY; - load_url_in_tab(tab, tab->hist_cur->h, NULL, 1); + load_url_in_tab(tab, tab->hist_cur->h, NULL, LU_MODE_NOHIST); } } blob - a9fe9346950d8564d4f1521ac6f9d019bf31410a blob + 7fcf75cf637f7bfe42ea3a20143de5c27bd7d479 --- telescope.c +++ telescope.c @@ -133,7 +133,7 @@ static int load_via_proxy(struct tab *, const char * static int make_request(struct tab *, struct get_req *, int, const char *); static int make_fs_request(struct tab *, int, const char *); -static int do_load_url(struct tab *, const char *, const char *); +static int do_load_url(struct tab *, const char *, const char *, int); static pid_t start_child(enum telescope_process, const char *, int); static struct proto { @@ -424,7 +424,7 @@ handle_imsg_got_meta(struct imsg *imsg, size_t datalen load_page_from_str(tab, err_pages[TOO_MUCH_REDIRECTS]); } else - do_load_url(tab, tab->meta, NULL); + do_load_url(tab, tab->meta, NULL, LU_MODE_NOCACHE); } else { /* 4x, 5x & 6x */ load_page_from_str(tab, err_pages[tab->code]); } @@ -925,7 +925,7 @@ err: * page synchronously. */ static int -do_load_url(struct tab *tab, const char *url, const char *base) +do_load_url(struct tab *tab, const char *url, const char *base, int mode) { struct phos_uri uri; struct proto *p; @@ -954,7 +954,7 @@ do_load_url(struct tab *tab, const char *url, const ch phos_serialize_uri(&tab->uri, tab->hist_cur->h, sizeof(tab->hist_cur->h)); - if (try_load_cache(tab)) + if (!(mode & LU_MODE_NOCACHE) && try_load_cache(tab)) return 0; for (p = protos; p->schema != NULL; ++p) { @@ -981,9 +981,10 @@ do_load_url(struct tab *tab, const char *url, const ch * prepare the url but don't load it. */ void -load_url(struct tab *tab, const char *url, const char *base, int nohist) +load_url(struct tab *tab, const char *url, const char *base, int mode) { int lazy = tab->flags & TAB_LAZY; + int nohist = mode & LU_MODE_NOHIST; if (!nohist && (!lazy || tab->hist_cur == NULL)) { if (tab->hist_cur != NULL) @@ -1006,14 +1007,14 @@ load_url(struct tab *tab, const char *url, const char } if (!lazy) - do_load_url(tab, url, base); + do_load_url(tab, url, base, mode); } void -load_url_in_tab(struct tab *tab, const char *url, const char *base, int nohist) +load_url_in_tab(struct tab *tab, const char *url, const char *base, int mode) { if (!operating) { - load_url(tab, url, base, nohist); + load_url(tab, url, base, mode); return; } @@ -1021,7 +1022,7 @@ load_url_in_tab(struct tab *tab, const char *url, cons message("Loading %s...", url); start_loading_anim(tab); - load_url(tab, url, base, nohist); + load_url(tab, url, base, mode); } int @@ -1032,7 +1033,7 @@ load_previous_page(struct tab *tab) if ((h = TAILQ_PREV(tab->hist_cur, mhisthead, entries)) == NULL) return 0; tab->hist_cur = h; - do_load_url(tab, h->h, NULL); + do_load_url(tab, h->h, NULL, LU_MODE_NONE); return 1; } @@ -1044,7 +1045,7 @@ load_next_page(struct tab *tab) if ((h = TAILQ_NEXT(tab->hist_cur, entries)) == NULL) return 0; tab->hist_cur = h; - do_load_url(tab, h->h, NULL); + do_load_url(tab, h->h, NULL, LU_MODE_NONE); return 1; } blob - 5facedbac001028d9b4a2f887d3d3b715606ffe2 blob + d1b876a21449a636a63d9dc5bcf516bdb4d818c3 --- telescope.h +++ telescope.h @@ -321,6 +321,10 @@ void sandbox_fs_process(void); /* telescope.c */ extern int operating; extern int safe_mode; + +#define LU_MODE_NONE 0x0 +#define LU_MODE_NOHIST 0x1 +#define LU_MODE_NOCACHE 0x2 void gopher_send_search_req(struct tab *, const char *); void load_url(struct tab *, const char *, const char *, int);