Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions ISSUE_77_FIX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Fix for Issue #77: Frequent duplicates on default page

This fix addresses the issue of duplicate activities appearing on the default page of the Sugar Labs Activities Store (ASLO-v4).

## Problem

Activities were appearing multiple times on the default page of the activities store. This was happening due to two main reasons:

1. The `index.json` file could potentially contain duplicate entries for the same activities
2. The frontend JavaScript code didn't check for duplicates when displaying activities

## Solution

The fix consists of two parts:

### 1. Frontend Fix (search.js)

Added duplicate checking in the `loadAllActivities()` function in `search.js`:
- Created a Set to track bundle_ids that have already been added to the page
- Only add an activity card if its bundle_id hasn't been seen before

This ensures that even if the `index.json` file contains duplicates, they won't be displayed on the page.

### 2. Backend Fix (generator.py)

Modified the index generation in `generator.py`:
- Before adding a new activity to the index, check if an activity with the same bundle_id already exists
- If it exists, update the existing entry instead of adding a duplicate
- Only add new entries for activities that don't already exist in the index

This prevents duplicates from being added to the `index.json` file in the first place.

## Testing

To test this fix:
1. Generate the activities store with `python -m aslo4 -i ./activities -b -g -p ./aslo4-static`
2. Open the generated site and verify that no duplicate activities appear on the default page
3. Search for activities and verify that search results don't contain duplicates

## Additional Notes

This fix maintains all the existing functionality while ensuring each activity appears only once on the page. The changes are minimal and focused on solving the specific issue without introducing new problems.
31 changes: 31 additions & 0 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Fix for Issue #77: Frequent duplicates on default page

## Description
This PR fixes the issue of duplicate activities appearing on the default page of the Sugar Labs Activities Store (ASLO-v4).

## Related Issue
Fixes #77

## Approach
The fix consists of two parts:

1. **Frontend Fix (search.js)**:
- Added duplicate checking in the `loadAllActivities()` function
- Created a Set to track bundle_ids that have already been added to the page
- Only add an activity card if its bundle_id hasn't been seen before

2. **Backend Fix (generator.py)**:
- Modified the index generation to check for existing bundle_ids
- Update existing entries instead of adding duplicates
- Only add new entries for activities that don't already exist in the index

## Testing Done
- Generated the activities store with test activities
- Verified no duplicate activities appear on the default page
- Tested search functionality to ensure no duplicates in search results

## Screenshots (if applicable)
[Add screenshots here if available]

## Additional Notes
This fix maintains all the existing functionality while ensuring each activity appears only once on the page. The changes are minimal and focused on solving the specific issue without introducing new problems.
16 changes: 14 additions & 2 deletions aslo4-static/js/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,31 @@ function loadAllActivities() {
miniSearch.addAll(data);
}
const results = miniSearch.search($('#saas-search-box').val());
// Track bundle_ids to prevent duplicates
const addedBundleIds = new Set();
$.each(results, function(i, item) {
addActivityCard(item);
// Only add the activity if its bundle_id hasn't been added yet
if (!addedBundleIds.has(item.bundle_id)) {
addActivityCard(item);
addedBundleIds.add(item.bundle_id);
}
});
});
} else {
$.getJSON('index.json', function(data) {
// Track bundle_ids to prevent duplicates
const addedBundleIds = new Set();
// update the UI with each card
$.each(
data.sort(function(el1, el2) {
return compareAlphabetically(el1, el2, 'name');
}),
function(i, item) {
addActivityCard(item);
// Only add the activity if its bundle_id hasn't been added yet
if (!addedBundleIds.has(item.bundle_id)) {
addActivityCard(item);
addedBundleIds.add(item.bundle_id);
}
});
});
}
Expand Down
29 changes: 25 additions & 4 deletions aslo4/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,14 +841,35 @@ def generate_web_page(

# update the index files
logger.debug("[STATIC][{}] Adding JSON".format(bundle.get_name()))
self.index.append(
bundle.generate_fingerprint_json(unique_icons=args.unique_icons)
)

# Get the bundle_id
bundle_id = bundle.get_bundle_id()

# Use a dictionary to track bundle_ids for efficient lookup
# Initialize the dictionary if it doesn't exist yet
if not hasattr(self, 'bundle_id_index'):
self.bundle_id_index = {}
# Populate with existing bundles
for idx, existing_bundle in enumerate(self.index):
if 'bundle_id' in existing_bundle:
self.bundle_id_index[existing_bundle['bundle_id']] = idx

# Check if this bundle_id already exists in the index
if bundle_id in self.bundle_id_index:
# Update the existing entry instead of adding a duplicate
idx = self.bundle_id_index[bundle_id]
self.index[idx] = bundle.generate_fingerprint_json(unique_icons=args.unique_icons)
else:
# Add to index if it doesn't already exist
self.index.append(
bundle.generate_fingerprint_json(unique_icons=args.unique_icons)
)
# Update the lookup dictionary
self.bundle_id_index[bundle_id] = len(self.index) - 1

# check the database and then update if necessary
# this will help to check if new bundles are created, and then
# accordingly call a hook.
bundle_id = bundle.get_bundle_id()
bundle_version = bundle.get_version()

saved_bundle_version = feed_json_data["bundles"].get(bundle_id)
Expand Down