|
a/Allura/allura/model/index.py |
|
b/Allura/allura/model/index.py |
1 |
import re
|
1 |
import re
|
2 |
import logging
|
2 |
import logging
|
3 |
from itertools import groupby
|
3 |
from itertools import groupby
|
4 |
from cPickle import dumps, loads
|
4 |
from cPickle import dumps, loads
|
5 |
from collections import defaultdict
|
5 |
from collections import defaultdict
|
|
|
6 |
from urllib import unquote
|
6 |
|
7 |
|
7 |
import bson
|
8 |
import bson
|
8 |
import pymongo
|
9 |
import pymongo
|
9 |
from pylons import c
|
10 |
from pylons import c
|
10 |
|
11 |
|
|
... |
|
... |
134 |
parsed_links = dict((link, cls._parse_link(link)) for link in links)
|
135 |
parsed_links = dict((link, cls._parse_link(link)) for link in links)
|
135 |
links_by_artifact = defaultdict(list)
|
136 |
links_by_artifact = defaultdict(list)
|
136 |
project_ids = set()
|
137 |
project_ids = set()
|
137 |
for link, d in parsed_links.iteritems():
|
138 |
for link, d in parsed_links.iteritems():
|
138 |
project_ids.add(d['project_id'])
|
139 |
project_ids.add(d['project_id'])
|
139 |
links_by_artifact[d['artifact']].append(d)
|
140 |
links_by_artifact[unquote(d['artifact'])].append(d)
|
140 |
q = cls.query.find(dict(
|
141 |
q = cls.query.find(dict(
|
141 |
link={'$in': links_by_artifact.keys()},
|
142 |
link={'$in': links_by_artifact.keys()},
|
142 |
project_id={'$in': list(project_ids)}
|
143 |
project_id={'$in': list(project_ids)}
|
143 |
), validate=False)
|
144 |
), validate=False)
|
144 |
result = {}
|
145 |
result = {}
|
145 |
matches_by_artifact = dict(
|
146 |
matches_by_artifact = dict(
|
146 |
(link, list(matches))
|
147 |
(link, list(matches))
|
147 |
for link, matches in groupby(q, key=lambda s:s.link))
|
148 |
for link, matches in groupby(q, key=lambda s:unquote(s.link)))
|
148 |
result = {}
|
149 |
result = {}
|
149 |
for link, d in parsed_links.iteritems():
|
150 |
for link, d in parsed_links.iteritems():
|
150 |
matches = matches_by_artifact.get(d['artifact'], [])
|
151 |
matches = matches_by_artifact.get(unquote(d['artifact']), [])
|
151 |
matches = (
|
152 |
matches = (
|
152 |
m for m in matches
|
153 |
m for m in matches
|
153 |
if m.project.shortname == d['project'] and
|
154 |
if m.project.shortname == d['project'] and
|
154 |
m.project.neighborhood_id == d['nbhd'] and
|
155 |
m.project.neighborhood_id == d['nbhd'] and
|
155 |
m.app_config is not None and
|
156 |
m.app_config is not None and
|