Skip to content

Commit b342ea6

Browse files
committed
Hardcode negated UID querying to AND operator
1 parent 42f727e commit b342ea6

File tree

2 files changed

+167
-1
lines changed

2 files changed

+167
-1
lines changed

redical_core/src/queries/query_parser.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,14 @@ macro_rules! fold_negated_terms {
165165
}}
166166
}
167167

168+
// Operator is hardcoded for UIDs due to the mutual exclusivity between separate
169+
// events (ie an event can't have multiple UIDs).
168170
fn build_uid_property_condition(property: &XUIDProperty) -> Option<WhereConditional> {
169171
if property.negated {
170172
fold_negated_terms!(
171173
UID,
172174
property.get_uids(),
173-
WhereOperator::Or
175+
WhereOperator::And
174176
)
175177
} else {
176178
fold_terms!(

tests/integration.rs

+164
Original file line numberDiff line numberDiff line change
@@ -1766,6 +1766,87 @@ mod integration {
17661766
]
17671767
);
17681768

1769+
// Assert negative querying by UID
1770+
query_calendar_and_assert_matching_event_instances!(
1771+
connection,
1772+
"TEST_CALENDAR_UID",
1773+
[
1774+
"(X-UID-NOT:EVENT_IN_CHELTENHAM_TUE_THU,OVERRIDDEN_EVENT_IN_BRISTOL_TUE_THU)",
1775+
"X-LIMIT:4",
1776+
"X-OFFSET:0",
1777+
"X-TZID:Europe/Vilnius",
1778+
"X-ORDER-BY:DTSTART-GEO-DIST;51.454481838260214;-2.588329192623361",
1779+
],
1780+
[
1781+
[
1782+
[
1783+
"DTSTART;TZID=Europe/Vilnius:20201231T200000",
1784+
"X-GEO-DIST:111.491952KM",
1785+
],
1786+
[
1787+
"CATEGORIES:CATEGORY_ONE,CATEGORY_THREE",
1788+
"DTEND;TZID=Europe/Vilnius:20201231T203000",
1789+
"DTSTART;TZID=Europe/Vilnius:20201231T200000",
1790+
"DURATION:PT30M",
1791+
"GEO:51.45442303961853;-0.9792277140273513",
1792+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20201231T200000",
1793+
"RELATED-TO;RELTYPE=PARENT:PARENT_UID",
1794+
"SUMMARY:Event in Reading on Tuesdays and Thursdays at 6:00PM",
1795+
"UID:EVENT_IN_READING_TUE_THU",
1796+
],
1797+
],
1798+
[
1799+
[
1800+
"DTSTART;TZID=Europe/Vilnius:20201231T203000",
1801+
"X-GEO-DIST:170.540546KM",
1802+
],
1803+
[
1804+
"CATEGORIES:CATEGORY_FOUR,CATEGORY_ONE",
1805+
"DTEND;TZID=Europe/Vilnius:20201231T210000",
1806+
"DTSTART;TZID=Europe/Vilnius:20201231T203000",
1807+
"DURATION:PT30M",
1808+
"GEO:51.50740017561507;-0.12698231869919185",
1809+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20201231T203000",
1810+
"RELATED-TO;RELTYPE=PARENT:PARENT_UID",
1811+
"SUMMARY:Event in London on Tuesdays and Thursdays at 6:30PM",
1812+
"UID:EVENT_IN_LONDON_TUE_THU",
1813+
],
1814+
],
1815+
[
1816+
[
1817+
"DTSTART;TZID=Europe/Vilnius:20210104T180000",
1818+
],
1819+
[
1820+
"CATEGORIES:CATEGORY TWO,CATEGORY_ONE",
1821+
"DTEND;TZID=Europe/Vilnius:20210104T190000",
1822+
"DTSTART;TZID=Europe/Vilnius:20210104T180000",
1823+
"DURATION:PT1H",
1824+
"LOCATION-TYPE:DIGITAL,ONLINE",
1825+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20210104T180000",
1826+
"SUMMARY:Online Event on Mondays and Wednesdays at 4:00PM",
1827+
"UID:ONLINE_EVENT_MON_WED",
1828+
],
1829+
],
1830+
[
1831+
[
1832+
"DTSTART;TZID=Europe/Vilnius:20210104T190000",
1833+
"X-GEO-DIST:97.489206KM",
1834+
],
1835+
[
1836+
"CATEGORIES:OVERRIDDEN_CATEGORY",
1837+
"DTEND;TZID=Europe/Vilnius:20210104T193000",
1838+
"DTSTART;TZID=Europe/Vilnius:20210104T190000",
1839+
"DURATION:PT30M",
1840+
"GEO:51.751365550307604;-1.2601196837753945",
1841+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20210104T190000",
1842+
"RELATED-TO;RELTYPE=PARENT:OVERRIDDEN_PARENT_UID",
1843+
"SUMMARY:Overridden event in Oxford summary text",
1844+
"UID:EVENT_IN_OXFORD_MON_WED",
1845+
],
1846+
],
1847+
]
1848+
);
1849+
17691850
assert_error_returned!(
17701851
connection,
17711852
"Error: - expected iCalendar RFC-5545 DATE-VALUE (DATE-FULLYEAR DATE-MONTH DATE-MDAY) at \"41T180000Z\" -- Context: X-UNTIL -> DATE-TIME -> DATE",
@@ -2076,6 +2157,89 @@ mod integration {
20762157
],
20772158
);
20782159

2160+
// Assert negative querying by UID
2161+
query_calendar_and_assert_matching_event_instances!(
2162+
connection,
2163+
"TEST_CALENDAR_UID",
2164+
[
2165+
"(X-UID-NOT:ONLINE_EVENT_MON_WED,OVERRIDDEN_EVENT_IN_BRISTOL_TUE_THU)",
2166+
"X-LIMIT:4",
2167+
"X-OFFSET:0",
2168+
"X-TZID:Europe/Vilnius",
2169+
"X-ORDER-BY:DTSTART-GEO-DIST;51.454481838260214;-2.588329192623361",
2170+
],
2171+
[
2172+
[
2173+
[
2174+
"DTSTART;TZID=Europe/Vilnius:20201231T200000",
2175+
"X-GEO-DIST:111.491952KM",
2176+
],
2177+
[
2178+
"DTEND;TZID=Europe/Vilnius:20201231T203000",
2179+
"DTSTART;TZID=Europe/Vilnius:20201231T200000",
2180+
"DURATION:PT30M",
2181+
"GEO:51.45442303961853;-0.9792277140273513",
2182+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20201231T200000",
2183+
"SUMMARY:Event in Reading on Tuesdays and Thursdays at 6:00PM",
2184+
"UID:EVENT_IN_READING_TUE_THU",
2185+
],
2186+
],
2187+
[
2188+
[
2189+
"DTSTART;TZID=Europe/Vilnius:20201231T203000",
2190+
"X-GEO-DIST:170.540546KM",
2191+
],
2192+
[
2193+
"CATEGORIES:OVERRIDDEN_CATEGORY",
2194+
"CLASS:OVERRIDDEN",
2195+
"DTEND;TZID=Europe/Vilnius:20201231T210000",
2196+
"DTSTART;TZID=Europe/Vilnius:20201231T203000",
2197+
"DURATION:PT30M",
2198+
"GEO:51.50740017561507;-0.12698231869919185",
2199+
"LOCATION-TYPE:OVERRIDDEN_TYPE",
2200+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20201231T203000",
2201+
"RELATED-TO;RELTYPE=PARENT:OVERIDDEN_UID",
2202+
"SUMMARY:Overridden Event in Cheltenham running in London",
2203+
"UID:EVENT_IN_CHELTENHAM_TUE_THU",
2204+
],
2205+
],
2206+
[
2207+
[
2208+
"DTSTART;TZID=Europe/Vilnius:20201231T223000",
2209+
"X-GEO-DIST:170.540546KM",
2210+
],
2211+
[
2212+
"CATEGORIES:OVERRIDDEN_CATEGORY",
2213+
"CLASS:OVERRIDDEN",
2214+
"DTEND;TZID=Europe/Vilnius:20201231T230000",
2215+
"DTSTART;TZID=Europe/Vilnius:20201231T223000",
2216+
"DURATION:PT30M",
2217+
"GEO:51.50740017561507;-0.12698231869919185",
2218+
"LOCATION-TYPE:OVERRIDDEN_TYPE",
2219+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20201231T223000",
2220+
"RELATED-TO;RELTYPE=PARENT:OVERIDDEN_UID",
2221+
"SUMMARY:Overridden Event in Bristol running in London",
2222+
"UID:EVENT_IN_BRISTOL_TUE_THU",
2223+
],
2224+
],
2225+
[
2226+
[
2227+
"DTSTART;TZID=Europe/Vilnius:20210105T200000",
2228+
"X-GEO-DIST:111.491952KM",
2229+
],
2230+
[
2231+
"DTEND;TZID=Europe/Vilnius:20210105T203000",
2232+
"DTSTART;TZID=Europe/Vilnius:20210105T200000",
2233+
"DURATION:PT30M",
2234+
"GEO:51.45442303961853;-0.9792277140273513",
2235+
"RECURRENCE-ID;VALUE=DATE-TIME;TZID=Europe/Vilnius:20210105T200000",
2236+
"SUMMARY:Event in Reading on Tuesdays and Thursdays at 6:00PM",
2237+
"UID:EVENT_IN_READING_TUE_THU",
2238+
],
2239+
]
2240+
]
2241+
);
2242+
20792243
// Assert comprehensive impossible query
20802244
query_calendar_and_assert_matching_events!(
20812245
connection,

0 commit comments

Comments
 (0)