Skip to content

Commit fc43315

Browse files
SamChou19815facebook-github-bot
authored andcommitted
[flow][indexing] Diff the new_available_exports_index and old_available_exports_index
Summary: This stack aims to fix the bug that incremental update of exports will incorrectly drop some export count to zero, because the current subtract function will incorrectly remove the entire export even through it will be added back. This diff fixes the issue by first diffing the available export index into two disjoint index for additional and removal, which are then passes to `Export_index.merge` and `Export_index.subtract`. This ensures that for the overlapping old and new available index that's supposed to cancel out, they won't incorrectly nuke the usage count entry. Changelog: [fix] Fixed a bug that causes incorrect updates to our index that tracks usage of exports, which leads to incorrect autoimport-ranked-by-usage results. Reviewed By: panagosg7 Differential Revision: D69694640 fbshipit-source-id: 9f777f69db78d05b49b373f68531b1d777590763
1 parent 81f82d4 commit fc43315

File tree

3 files changed

+35
-4
lines changed

3 files changed

+35
-4
lines changed

src/services/export/index/export_index.ml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,29 @@ let fold ~f ~init t =
132132

133133
let map ~f t = SMap.map (ExportMap.map f) t
134134

135+
let diff ~old_index ~new_index =
136+
let exist_in_index export_name export_key map =
137+
match SMap.find_opt export_name map with
138+
| None -> false
139+
| Some map -> ExportMap.mem export_key map
140+
in
141+
let diff_index l r =
142+
SMap.fold
143+
(fun export_name map acc ->
144+
ExportMap.fold
145+
(fun export_key _ acc ->
146+
if exist_in_index export_name export_key r then
147+
acc
148+
else
149+
let (s, k) = export_key in
150+
add export_name s k acc)
151+
map
152+
acc)
153+
l
154+
SMap.empty
155+
in
156+
(diff_index new_index old_index, diff_index old_index new_index)
157+
135158
let subtract old_t t =
136159
let (t, dead_names) =
137160
SMap.fold

src/services/export/index/export_index.mli

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ val merge : t -> t -> t
3737

3838
val merge_export_import : t -> t -> t
3939

40+
(* Returns tuple of two disjoint index: (addition_index, removal_index),
41+
* to be passed to [merge] and `[subtract]`. *)
42+
val diff : old_index:t -> new_index:t -> t * t
43+
4044
(** [subtract to_remove t] removes all of the exports in [to_remove] from [t], and
4145
also returns a list of keys that no longer are exported by any file. *)
4246
val subtract : t -> t -> t * string list

src/services/export/search/export_search.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,16 @@ let init index =
6767
let type_matcher = Fuzzy_path.init types in
6868
{ index; value_matcher; type_matcher }
6969

70-
let merge_available_exports old_index new_index { index; value_matcher; type_matcher } =
71-
let (index, dead_candidates) = Export_index.subtract old_index index in
70+
let merge_available_exports
71+
old_available_exports_index new_available_exports_index { index; value_matcher; type_matcher } =
72+
let (addition_index, removal_index) =
73+
Export_index.diff ~old_index:old_available_exports_index ~new_index:new_available_exports_index
74+
in
75+
let (index, dead_candidates) = Export_index.subtract removal_index index in
7276
let value_matcher = Fuzzy_path.remove_candidates value_matcher dead_candidates in
7377
let type_matcher = Fuzzy_path.remove_candidates type_matcher dead_candidates in
74-
let index = Export_index.merge new_index index in
75-
let { values; types } = partition_candidates new_index in
78+
let index = Export_index.merge addition_index index in
79+
let { values; types } = partition_candidates addition_index in
7680
let value_matcher = Fuzzy_path.add_candidates value_matcher values in
7781
let type_matcher = Fuzzy_path.add_candidates type_matcher types in
7882
{ index; value_matcher; type_matcher }

0 commit comments

Comments
 (0)