Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

core: avoid db look up in m_category:id_to_name/2.

  • Loading branch information...
commit 9ee9c9ade3d221fff1363bc9606a9bfe613e404d 1 parent 14f0cae
@kaos kaos authored
Showing with 1 addition and 2 deletions.
  1. +1 −2  src/models/m_category.erl
View
3  src/models/m_category.erl
@@ -226,8 +226,7 @@ name_to_id_check(Name, Context) ->
id_to_name(Name, Context) when is_atom(Name); is_binary(Name); is_list(Name) ->
F = fun() ->
- Nm = z_db:q1("select r.name from rsc r join category c on r.id = c.id where r.name = $1", [Name], Context),
- z_convert:to_atom(Nm)
+ z_convert:to_atom(Name)
end,
z_depcache:memo(F, {category_id_to_name, Name}, ?WEEK, [category], Context);
id_to_name(Id, Context) when is_integer(Id) ->

4 comments on commit 9ee9c9a

@arjan
Owner

Why is this?
The lookup is done to ensure that the name exists in the database.

But, if you remove this, you should also remove the memocaching construct, as you're now just caching z_convert:to_atom.

@kaos
Owner

Ah, good point.
I didn't expect/think of the effect of having the name validated... which I find rather useful, so I'll revert it with some comments added.
And the caching should've been removed too, as you say.

The reason why I found this spot and "fixed" it, is due to my recent work on the rbac module, for which I have eunit tests - but I don't want to rely on having a db ;)
So I solved it by pre-filling the depcache with data for any queries needed by the tests.
(if you're curious take a look at the rbac branch in my fork of zotonic)

@arjan
Owner

Cool! I'll have a look.

And I tought you did all that work because you were working on the auth manuals... ;-)

@kaos
Owner

heh... yeah. That goes hand in hand. I'm learning more about auth and acl when doing rbac, so I can document it ;-)

Please sign in to comment.
Something went wrong with that request. Please try again.