Skip to content

Commit

Permalink
Fix initial indexing bug #560
Browse files Browse the repository at this point in the history
  • Loading branch information
joepio committed Jan 19, 2023
1 parent ccd3638 commit d003a9d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ See [STATUS.md](server/STATUS.md) to learn more about which features will remain
- Add `--force` to `atomic-server import` #536
- Fix index issue happening when deleting a single property in a sorted collection #545
- Update JS assets & playwright
- Fix initial indexing bug #560

## [v0.34.0] - 2022-10-31

Expand Down
23 changes: 13 additions & 10 deletions server/src/appstate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,9 @@ pub fn init(config: Config) -> AtomicServerResult<AppState> {
store.build_index(true)?;
tracing::info!("Building index finished!");
}

tracing::info!("Setting default agent");
set_default_agent(&config, &store)?;
if config.initialize {
tracing::info!(
"Running initialization commands (first time startup, or you passed --initialize)"
);
store.populate()?;
set_up_initial_invite(&store)
.map_err(|e| format!("Error while setting up initial invite: {}", e))?;
// This means that editing the .env does _not_ grant you the rights to edit the Drive.
tracing::info!("Setting rights to Drive {}", store.get_server_url());
}

// Initialize search constructs
tracing::info!("Starting search service");
Expand All @@ -87,6 +78,18 @@ pub fn init(config: Config) -> AtomicServerResult<AppState> {
};
store.set_handle_commit(Box::new(send_commit));

if config.initialize {
tracing::info!(
"Running initialization commands (first time startup, or you passed --initialize)"
);
store.populate()?;

set_up_initial_invite(&store)
.map_err(|e| format!("Error while setting up initial invite: {}", e))?;
// This means that editing the .env does _not_ grant you the rights to edit the Drive.
tracing::info!("Setting rights to Drive {}", store.get_server_url());
}

Ok(AppState {
store,
config,
Expand Down
4 changes: 4 additions & 0 deletions server/src/search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,19 @@ pub fn get_schema_fields(appstate: &SearchState) -> AtomicServerResult<Fields> {
/// Indexes all resources from the store to search.
/// At this moment does not remove existing index.
pub fn add_all_resources(search_state: &SearchState, store: &Db) -> AtomicServerResult<()> {
tracing::info!("Building search index...");

let resources = store
.all_resources(true)
.filter(|resource| !resource.get_subject().contains("/commits/"));

for resource in resources {
println!("Indexing {}", resource.get_subject());
add_resource(search_state, &resource, store)?;
}

search_state.writer.write()?.commit()?;
tracing::info!("Search index finished!");
Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions server/src/serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ fn rebuild_index(appstate: &crate::appstate::AppState) -> AtomicServerResult<()>
.write()
.expect("Could not get a lock on search writer")
.delete_all_documents()?;
tracing::info!("Building search index...");
crate::search::add_all_resources(&appstate_clone.search_state, &appstate.store)?;
tracing::info!("Search index finished!");
Ok(())
}

Expand Down

0 comments on commit d003a9d

Please sign in to comment.