This works and matches the pattern of def app_config() but since this method will be called frequently (every nbhd root request), I think we should change it to use self.app_configs which is a list that is already loaded into memory.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
--- a/Allura/allura/model/project.py+++ b/Allura/allura/model/project.py@@ -515,9 +515,9 @@ def app_config(self, mount_point):
'options.mount_point':mount_point}).first()
def app_config_by_tool_type(self, tool_type):
- return AppConfig.query.find({- 'project_id': self._id,- 'tool_name': tool_type}).first()+ for ac in self.app_configs:+ if ac.tool_name == tool_type:+ return ac
but got failed test:
======================================================================
ERROR: allura.tests.test_commands.test_update_neighborhood
----------------------------------------------------------------------
Traceback (most recent call last):
File "/var/tmp/buildenv/1a26a3f8009f89f489415fb1c0b257ece5282961/lib/python2.7/site-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/deploy/buildbot/slave2/full/build/Allura/allura/tests/test_commands.py", line 124, in test_update_neighborhood
cmd.command()
File "/home/deploy/buildbot/slave2/full/build/Allura/allura/command/create_neighborhood.py", line 69, in command
p.install_app('home', 'home', 'Home', ordinal=0)
File "/home/deploy/buildbot/slave2/full/build/Allura/allura/model/project.py", line 472, in install_app
'Mount point "%s" is already in use' % mount_point)
ToolError: Mount point "home" is already in use
After some debugging I found out that results of self.app_configs and querying the database directly differs:
ipdb> for ac in p.app_configs: print ac.project_id, ac.tool_name, ac.options['ordinal']
4ffaa7828fd0922bc2000286 admin 2
4ffaa7828fd0922bc2000286 Wiki 1
ipdb> for ac in M.AppConfig.query.find({'project_id': p._id}): print ac.project_id, ac.tool_name, ac.options['ordinal']
4ffaa7828fd0922bc2000286 admin 2
4ffaa7828fd0922bc2000286 home 0
4ffaa7828fd0922bc2000286 Wiki 1
Seems like self.app_configs contains cached result, but I can't find a way to update it properly.
Could you point me in the right direction?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I've encountered the same issue once before. I wish install_app() would refresh the app_configs list, but I don't think there is a way to do that, and its possible to work around it fairly well.
There were two parts of the problem:
In the test, cmd.run() runs the command, and cmd.command() is unnecessary. It runs it again.
If you close the session after the command is run, and before checking the result, then the Project object is queried anew, so it gets the latest values for everything.
I went ahead and committed [58e0e2] using your changes, plus those 2 fixes. I've pushed it on dev, so you can look at it.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This will have the affect of avoiding project queries in the 2nd half of the nbhd index() method.
created #95: [#4457] Fix has_home_tool() implementation (1cp)
Related
Tickets:
#4457closed #95 and pushed changes into 42cc_4457
This works and matches the pattern of
def app_config()
but since this method will be called frequently (every nbhd root request), I think we should change it to useself.app_configs
which is a list that is already loaded into memory.created #107: [#4457] Use self.app_configs instead of quering database each time (1cp)
Related
Tickets:
#4457I made the following changes:
but got failed test:
After some debugging I found out that results of
self.app_configs
and querying the database directly differs:Seems like
self.app_configs
contains cached result, but I can't find a way to update it properly.Could you point me in the right direction?
I've encountered the same issue once before. I wish install_app() would refresh the app_configs list, but I don't think there is a way to do that, and its possible to work around it fairly well.
There were two parts of the problem:
cmd.run()
runs the command, andcmd.command()
is unnecessary. It runs it again.I went ahead and committed [58e0e2] using your changes, plus those 2 fixes. I've pushed it on dev, so you can look at it.