Skip to content
This repository has been archived by the owner on Mar 18, 2024. It is now read-only.

Commit

Permalink
Fix options on low performance systems
Browse files Browse the repository at this point in the history
  • Loading branch information
qaqland committed Feb 5, 2024
1 parent f5acbdc commit 3d374f5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ CACHES := $(INDEXS:%APKINDEX.tar.gz=%cache.gob)

all: $(CACHES)

# sleep is needed on low performance server
%cache.gob: %APKINDEX.tar.gz
@$(AINDEX_BIN) -path $< -key $(MASTER_KEY) -url $(SEARCH_URL)
@$(AINDEX_BIN) -path $< -key $(MASTER_KEY) -url $(SEARCH_URL); sleep 60

.PHONY: clean
clean:
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ $ go build -o aindex main.go

## Init Settings in Meilisearch

pip install `meilisearch` first

```
$ ./init-search-index.py --help
$ python ./init-search-index.py --help
```

It delete old indexs and create new based on rsync file tree.

Move `indexes.json` to html's public dir
Move `indexes.json` to html's public dir and change KEY in `html/src/Key.jsx`

## Update Indexs in MeiliSearch

Expand Down
30 changes: 14 additions & 16 deletions init-search-index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@
import glob, os, sys
import json

try:
import meilisearch
except:
print("Install meilisearch package of python")
os.system("pip install meilisearch")
import meilisearch
finally:
from meilisearch.errors import MeilisearchError
import meilisearch
from meilisearch.errors import MeilisearchError

parser = argparse.ArgumentParser(
description="init meilisearch indexes(settings) and delete old",
Expand Down Expand Up @@ -44,23 +38,26 @@

has_key = False
for key in resp.results:
if len(key.actions) != 1 or key.actions[0] != "search":
if len(key.actions) != 2:
continue
actions = sorted(key.actions)
if actions[0] != "documents.get" or actions[1] != "search":
continue
if key.indexes[0] != "*":
continue
has_key = True
print(f"Search Key: {key.key}")
print(f"HTML Key: {key.key}")

if not has_key:
resp = client.create_key(
options={
"description": "Search API Key",
"actions": ["search"],
"description": "API Key: Search and Get Details",
"actions": ["search", "documents.get"],
"indexes": ["*"],
"expiresAt": None,
}
)
print(f"Search Key: {resp.key} (New)")
print(f"HTML Key: {resp.key} (New)")

resp = client.get_indexes()
count = resp["total"]
Expand All @@ -85,7 +82,7 @@
"description",
"origin",
"build_time",
"id", # react list need unique key
"id", # react list need unique key
],
"distinctAttribute": None,
"faceting": {"maxValuesPerFacet": 100},
Expand All @@ -109,7 +106,7 @@
for ipath in indexes:
parts = ipath.split("/")
index = f'{parts[-4].replace(".", "_")}_{parts[-2]}'
json_indexes.append({"arch":parts[-2], "branch":parts[-4]})
json_indexes.append({"arch": parts[-2], "branch": parts[-4]})
if index in has_indexes:
has_indexes.remove(index)
task = client.index(index).update_settings(settings)
Expand All @@ -122,8 +119,9 @@
print(f"{index:>16}: succeeded")

json_data = json.dumps(json_indexes)
with open('indexes.json', 'w') as file:
with open("indexes.json", "w") as file:
file.write(json_data)
print("Write Indexes to indexes.json")

for index in has_indexes:
print(f"Remove Unnecessary Index: {index}")
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ func main() {
err error
)
// custom time out
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Minute)
ctx, cancelFunc := context.WithTimeout(context.Background(), time.Minute*5)
defer cancelFunc()
option := meilisearch.WaitParams{
Context: ctx,
Interval: time.Millisecond * 50,
Interval: time.Millisecond * 100,
}
// delete old
delete_ids := make([]string, 0, len(base.LastSet))
Expand Down
6 changes: 6 additions & 0 deletions rsync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ rsync \
$src $des

# --delete \

# example make running:
# MIRROR_DIR=$des \
# MASTER_KEY=1234567890 \
# AINDEX_BIN=/home/qaq/projects/apkindex/aindex \
# make -f /home/qaq/Makefile

0 comments on commit 3d374f5

Please # to comment.