Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
Feature: Add filter to /messages. Add 'contains_url' to filter. #922
Conversation
erikjohnston
added some commits
Jul 14, 2016
erikjohnston
assigned
NegativeMjark
Jul 14, 2016
NegativeMjark
commented on the diff
Jul 14, 2016
| + ) | ||
| + args.extend(event_filter.senders) | ||
| + | ||
| + for sender in event_filter.not_senders: | ||
| + clauses.append("sender != ?") | ||
| + args.append(sender) | ||
| + | ||
| + if event_filter.rooms: | ||
| + clauses.append( | ||
| + "(%s)" % " OR ".join("room_id = ?" for _ in event_filter.rooms) | ||
| + ) | ||
| + args.extend(event_filter.rooms) | ||
| + | ||
| + for room_id in event_filter.not_rooms: | ||
| + clauses.append("room_id != ?") | ||
| + args.append(room_id) |
NegativeMjark
Contributor
|
NegativeMjark
commented on the diff
Jul 14, 2016
| +# distributed under the License is distributed on an "AS IS" BASIS, | ||
| +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| +# See the License for the specific language governing permissions and | ||
| +# limitations under the License. | ||
| + | ||
| +from synapse.storage.prepare_database import get_statements | ||
| + | ||
| +import logging | ||
| +import ujson | ||
| + | ||
| +logger = logging.getLogger(__name__) | ||
| + | ||
| + | ||
| +ALTER_TABLE = """ | ||
| +ALTER TABLE events ADD COLUMN sender TEXT; | ||
| +ALTER TABLE events ADD COLUMN contains_url BOOLEAN; |
NegativeMjark
Contributor
|
|
Amusingly postgres doesn't optimise out queries with
Gives:
|
|
Hmm, but it does optimise "a = 0 AND a = 1". How peculiar. |
NegativeMjark
commented on the diff
Jul 15, 2016
| @@ -95,6 +95,50 @@ def upper_bound(token, engine, inclusive=True): | ||
| ) | ||
| +def filter_to_clause(event_filter): | ||
| + if not event_filter: | ||
| + return "", [] | ||
| + | ||
| + clauses = [] | ||
| + args = [] | ||
| + | ||
| + if event_filter.types: | ||
| + clauses.append( | ||
| + "(%s)" % " OR ".join("type = ?" for _ in event_filter.types) | ||
| + ) | ||
| + args.extend(event_filter.types) |
NegativeMjark
Contributor
|
|
Also postgresql seems to optimise Running:
Gives:
|
|
(The tests are jenkins being unhappy) |
|
LGTM |
erikjohnston commentedJul 14, 2016
No description provided.