Skip to content

Commit 9123ebb

Browse files
Merge #597
597: Use task model for all settings helpers r=ellnix a=ellnix Noticed that I messed up creating the new settings helpers, should have used `Model::Task` all along. Co-authored-by: ellnix <[email protected]>
2 parents 085793f + 522696f commit 9123ebb

File tree

3 files changed

+70
-68
lines changed

3 files changed

+70
-68
lines changed

.rubocop_todo.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2025-01-10 14:26:27 UTC using RuboCop version 1.69.2.
3+
# on 2025-01-15 12:21:42 UTC using RuboCop version 1.69.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -10,12 +10,12 @@
1010
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
1111
# AllowedMethods: refine
1212
Metrics/BlockLength:
13-
Max: 702
13+
Max: 693
1414

1515
# Offense count: 4
1616
# Configuration parameters: CountComments, CountAsOne.
1717
Metrics/ClassLength:
18-
Max: 480
18+
Max: 492
1919

2020
# Offense count: 1
2121
# Configuration parameters: Max, CountKeywordArgs.

lib/meilisearch/index.rb

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -609,11 +609,15 @@ def proximity_precision
609609
end
610610

611611
def update_proximity_precision(proximity_precision_attribute)
612-
http_put("/indexes/#{@uid}/settings/proximity-precision", proximity_precision_attribute)
612+
response = http_put("/indexes/#{@uid}/settings/proximity-precision", proximity_precision_attribute)
613+
614+
Models::Task.new(response, task_endpoint)
613615
end
614616

615617
def reset_proximity_precision
616-
http_delete("/indexes/#{@uid}/settings/proximity-precision")
618+
response = http_delete("/indexes/#{@uid}/settings/proximity-precision")
619+
620+
Models::Task.new(response, task_endpoint)
617621
end
618622

619623
### SETTINGS - SEARCH CUTOFF MS
@@ -623,11 +627,15 @@ def search_cutoff_ms
623627
end
624628

625629
def update_search_cutoff_ms(search_cutoff_ms_attribute)
626-
http_put("/indexes/#{@uid}/settings/search-cutoff-ms", search_cutoff_ms_attribute)
630+
response = http_put("/indexes/#{@uid}/settings/search-cutoff-ms", search_cutoff_ms_attribute)
631+
632+
Models::Task.new(response, task_endpoint)
627633
end
628634

629635
def reset_search_cutoff_ms
630-
http_delete("/indexes/#{@uid}/settings/search-cutoff-ms")
636+
response = http_delete("/indexes/#{@uid}/settings/search-cutoff-ms")
637+
638+
Models::Task.new(response, task_endpoint)
631639
end
632640

633641
### SETTINGS - LOCALIZED ATTRIBUTES
@@ -639,11 +647,15 @@ def localized_attributes
639647
def update_localized_attributes(new_localized_attributes)
640648
new_localized_attributes = Utils.transform_attributes(new_localized_attributes)
641649

642-
http_put("/indexes/#{@uid}/settings/localized-attributes", new_localized_attributes)
650+
response = http_put("/indexes/#{@uid}/settings/localized-attributes", new_localized_attributes)
651+
652+
Models::Task.new(response, task_endpoint)
643653
end
644654

645655
def reset_localized_attributes
646-
http_delete("/indexes/#{@uid}/settings/localized-attributes")
656+
response = http_delete("/indexes/#{@uid}/settings/localized-attributes")
657+
658+
Models::Task.new(response, task_endpoint)
647659
end
648660

649661
### SETTINGS - FACET SEARCH
@@ -653,11 +665,15 @@ def facet_search_setting
653665
end
654666

655667
def update_facet_search_setting(new_facet_search_setting)
656-
http_put("/indexes/#{@uid}/settings/facet-search", new_facet_search_setting)
668+
response = http_put("/indexes/#{@uid}/settings/facet-search", new_facet_search_setting)
669+
670+
Models::Task.new(response, task_endpoint)
657671
end
658672

659673
def reset_facet_search_setting
660-
http_delete("/indexes/#{@uid}/settings/facet-search")
674+
response = http_delete("/indexes/#{@uid}/settings/facet-search")
675+
676+
Models::Task.new(response, task_endpoint)
661677
end
662678

663679
### SETTINGS - PREFIX SEARCH
@@ -667,11 +683,15 @@ def prefix_search
667683
end
668684

669685
def update_prefix_search(new_prefix_search_setting)
670-
http_put("/indexes/#{@uid}/settings/prefix-search", new_prefix_search_setting)
686+
response = http_put("/indexes/#{@uid}/settings/prefix-search", new_prefix_search_setting)
687+
688+
Models::Task.new(response, task_endpoint)
671689
end
672690

673691
def reset_prefix_search
674-
http_delete("/indexes/#{@uid}/settings/prefix-search")
692+
response = http_delete("/indexes/#{@uid}/settings/prefix-search")
693+
694+
Models::Task.new(response, task_endpoint)
675695
end
676696

677697
### SETTINGS - EMBEDDERS
@@ -683,11 +703,15 @@ def embedders
683703
def update_embedders(new_embedders)
684704
new_embedders = Utils.transform_attributes(new_embedders)
685705

686-
http_patch("/indexes/#{@uid}/settings/embedders", new_embedders)
706+
response = http_patch("/indexes/#{@uid}/settings/embedders", new_embedders)
707+
708+
Models::Task.new(response, task_endpoint)
687709
end
688710

689711
def reset_embedders
690-
http_delete("/indexes/#{@uid}/settings/embedders")
712+
response = http_delete("/indexes/#{@uid}/settings/embedders")
713+
714+
Models::Task.new(response, task_endpoint)
691715
end
692716
end
693717
end

spec/meilisearch/index/settings_spec.rb

Lines changed: 31 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -728,19 +728,15 @@
728728
end
729729

730730
it 'updates proximity precision' do
731-
update_task = index.update_proximity_precision('byAttribute')
732-
client.wait_for_task(update_task['taskUid'])
733-
731+
index.update_proximity_precision('byAttribute').await
734732
expect(index.proximity_precision).to eq('byAttribute')
735733
end
736734

737735
it 'resets proximity precision' do
738-
update_task = index.update_proximity_precision('byAttribute')
739-
client.wait_for_task(update_task['taskUid'])
740-
741-
reset_task = index.reset_proximity_precision
742-
client.wait_for_task(reset_task['taskUid'])
736+
index.update_proximity_precision('byAttribute').await
737+
expect(index.proximity_precision).to eq('byAttribute')
743738

739+
index.reset_proximity_precision.await
744740
expect(index.proximity_precision).to eq('byWord')
745741
end
746742
end
@@ -757,21 +753,15 @@
757753
end
758754

759755
it '#update_search_cutoff_ms updates default value' do
760-
update_task = index.update_search_cutoff_ms(800)
761-
client.wait_for_task(update_task['taskUid'])
762-
756+
index.update_search_cutoff_ms(800).await
763757
expect(index.search_cutoff_ms).to eq(800)
764758
end
765759

766760
it '#reset_search_cutoff_ms resets search cutoff ms' do
767-
update_task = index.update_search_cutoff_ms(300)
768-
client.wait_for_task(update_task['taskUid'])
769-
761+
index.update_search_cutoff_ms(300).await
770762
expect(index.search_cutoff_ms).to eq(300)
771763

772-
reset_task = index.reset_search_cutoff_ms
773-
client.wait_for_task(reset_task['taskUid'])
774-
764+
index.reset_search_cutoff_ms.await
775765
expect(index.search_cutoff_ms).to eq(default_search_cutoff_ms)
776766
end
777767
end
@@ -787,21 +777,25 @@
787777
end
788778

789779
it '#update_localized_attributes updates default value' do
790-
update_task = index.update_localized_attributes([{ attribute_patterns: ['title'], locales: ['eng'] }])
791-
client.wait_for_task(update_task['taskUid'])
780+
index.update_localized_attributes(
781+
[{ attribute_patterns: ['title'], locales: ['eng'] }]
782+
).await
792783

793-
expect(index.localized_attributes).to eq([{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }])
784+
expect(index.localized_attributes).to eq(
785+
[{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }]
786+
)
794787
end
795788

796789
it '#reset_localized_attributes resets localized attributes' do
797-
update_task = index.update_localized_attributes([{ attribute_patterns: ['title'], locales: ['eng'] }])
798-
client.wait_for_task(update_task['taskUid'])
799-
800-
expect(index.localized_attributes).to eq([{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }])
790+
index.update_localized_attributes(
791+
[{ attribute_patterns: ['title'], locales: ['eng'] }]
792+
).await
801793

802-
reset_task = index.reset_localized_attributes
803-
client.wait_for_task(reset_task['taskUid'])
794+
expect(index.localized_attributes).to eq(
795+
[{ 'attributePatterns' => ['title'], 'locales' => ['eng'] }]
796+
)
804797

798+
index.reset_localized_attributes.await
805799
expect(index.localized_attributes).to eq(default_localized_attributes)
806800
end
807801
end
@@ -817,21 +811,15 @@
817811
end
818812

819813
it '#update_facet_search_setting updates default value' do
820-
update_task = index.update_facet_search_setting(false)
821-
client.wait_for_task(update_task['taskUid'])
822-
814+
index.update_facet_search_setting(false).await
823815
expect(index.facet_search_setting).to eq(false)
824816
end
825817

826818
it '#reset_facet_search_setting resets facet search' do
827-
update_task = index.update_facet_search_setting(false)
828-
client.wait_for_task(update_task['taskUid'])
829-
819+
index.update_facet_search_setting(false).await
830820
expect(index.facet_search_setting).to eq(false)
831821

832-
reset_task = index.reset_facet_search_setting
833-
client.wait_for_task(reset_task['taskUid'])
834-
822+
index.reset_facet_search_setting.await
835823
expect(index.facet_search_setting).to eq(default_facet_search_setting)
836824
end
837825
end
@@ -847,21 +835,15 @@
847835
end
848836

849837
it '#update_prefix_search updates default value' do
850-
update_task = index.update_prefix_search('disabled')
851-
client.wait_for_task(update_task['taskUid'])
852-
838+
index.update_prefix_search('disabled').await
853839
expect(index.prefix_search).to eq('disabled')
854840
end
855841

856842
it '#reset_prefix_search resets prefix search' do
857-
update_task = index.update_prefix_search('disabled')
858-
client.wait_for_task(update_task['taskUid'])
859-
843+
index.update_prefix_search('disabled').await
860844
expect(index.prefix_search).to eq('disabled')
861845

862-
reset_task = index.reset_prefix_search
863-
client.wait_for_task(reset_task['taskUid'])
864-
846+
index.reset_prefix_search.await
865847
expect(index.prefix_search).to eq(default_prefix_search)
866848
end
867849
end
@@ -878,31 +860,27 @@
878860
end
879861

880862
it '#update_embedders updates default value' do
881-
update_task = index.update_embedders(
863+
index.update_embedders(
882864
custom: {
883865
source: 'userProvided',
884866
dimensions: 3
885867
}
886-
)
887-
client.wait_for_task(update_task['taskUid'])
868+
).await
888869

889870
expect(index.embedders).to have_key('custom')
890871
end
891872

892873
it '#reset_embedders resets embedders to nil' do
893-
update_task = index.update_embedders(
874+
index.update_embedders(
894875
custom: {
895876
source: 'userProvided',
896877
dimensions: 3
897878
}
898-
)
899-
client.wait_for_task(update_task['taskUid'])
879+
).await
900880

901881
expect(index.embedders).to have_key('custom')
902882

903-
reset_task = index.reset_embedders
904-
client.wait_for_task(reset_task['taskUid'])
905-
883+
index.reset_embedders.await
906884
expect(index.embedders).to eq(default_embedders)
907885
end
908886
end

0 commit comments

Comments
 (0)