Anniepoo / identity

A pack for SWI-Prolog web framework to handle usernames, login, signup, and other user management
Other
8 stars 1 forks source link

Improve indexing on status? #5

Closed pmoura closed 4 years ago

pmoura commented 4 years ago

If you change the following line:

https://github.com/Anniepoo/identity/blob/83a90ed939d06988ad2fd5e2c8b72d3bd0ccb2ca/prolog/identity/login_page.pl#L216

to e.g.

new_status_if_remembering(Status, _, _, other(Status)).

then you can rewrite the clause:

do_actual_login(Status, SuccessURL, _UserName, Request) :-
      Status \= ok,
      Status \= ok_remember,
      http_link_to_id(login_form,
                      [
                          warn(Status),
                          referer(SuccessURL)
                      ],
                      HREF),
      http_redirect(see_other, HREF, Request).

by writing instead:

do_actual_login(other(Status), SuccessURL, _UserName, Request) :-
      http_link_to_id(login_form,
                      [
                          warn(Status),
                          referer(SuccessURL)
                      ],
                      HREF),
      http_redirect(see_other, HREF, Request).

This will give first-argument indexing with no spurious choice-points for the do_actual_login/4 predicate without using cuts or \+/1 calls as in the original clause.

I can convert this suggestion into a pull request but I may be missing some detail as I only skimmed the code.

pmoura commented 4 years ago

You may also need a third clause for the new_status_if_remembering /4 predicate before the one with the suggestion:

new_status_if_remembering(ok_remember, _, _, ok_remember). 
Anniepoo commented 4 years ago

This is pretty straightforward code. I'd say just PR these.