From 3d374f52b6064ba613edb5d16dfec02651256acc Mon Sep 17 00:00:00 2001 From: qaqland Date: Mon, 5 Feb 2024 17:11:30 +0800 Subject: [PATCH] Fix options on low performance systems --- Makefile | 3 ++- README.md | 6 ++++-- init-search-index.py | 30 ++++++++++++++---------------- main.go | 4 ++-- rsync.sh | 6 ++++++ 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index d76e3de..99897d7 100644 --- a/Makefile +++ b/Makefile @@ -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: diff --git a/README.md b/README.md index 90620eb..8de1910 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/init-search-index.py b/init-search-index.py index 1038c5b..ee28c7a 100755 --- a/init-search-index.py +++ b/init-search-index.py @@ -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", @@ -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"] @@ -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}, @@ -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) @@ -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}") diff --git a/main.go b/main.go index 791eb41..ecdccf3 100644 --- a/main.go +++ b/main.go @@ -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)) diff --git a/rsync.sh b/rsync.sh index 1a3ee17..015c004 100755 --- a/rsync.sh +++ b/rsync.sh @@ -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